layout_weight is not working inside ScrollView
I can't figure out , why layout_weight is not working inside the ScrollView , when i am running this xml , i am getting imageview capturing the whole screen and below that i can see my tabs and the viewpager got hidden .
When i am giving the height in dp to all the linear layout below the ScrollView , i am getting my view perfectly ,why it's happening . i want my imageview to take 30% screen and tab/viewpager to take 70% of screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/gift_vouchr_header_img"
android:layout_weight="3"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="0dp"
android:orientation="vertical"
android:tag="sticky"
android:layout_weight="7"
android:adjustViewBounds="true"
android:layout_gravity="center"
>
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
When i remove weightsum and hardcoding the height then the view is working perfectly : below is my code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="@color/gift_vouchr_header_img"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="500dp"
android:orientation="vertical"
android:tag="sticky"
android:adjustViewBounds="true"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
MyTab1 xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_15"
android:layout_marginRight="@dimen/margin_15"
android:layout_marginTop="@dimen/margin_15"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_amount_footer_txt"
android:text="@string/validity"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/voucher_common_layout"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_title_txt"
android:layout_marginTop="@dimen/margin_26"
android:text="@string/receiver_detail"/>
<EditText
android:id="@+id/receiver_name"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:backgroundTint="@color/QuaternaryTextColor"
android:hint="@string/receiver_name"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_23"/>
<EditText
android:id="@+id/receiver_email"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:hint="@string/receiver_email"
android:inputType="textEmailAddress"
android:backgroundTint="@color/QuaternaryTextColor"
style="@style/giftEditetxtStyle"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_30"/>
<EditText
android:id="@+id/receiver_mobile"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:backgroundTint="@color/QuaternaryTextColor"
android:inputType="phone"
android:hint="@string/receiver_mobile"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_30"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginBottom="@dimen/margin_30"
android:layout_marginRight="@dimen/margin_12"
android:gravity="center"
android:orientation="horizontal">
<CheckBox
android:id="@+id/send_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_term_condition"
android:layout_marginLeft="@dimen/margin_5"
android:text="@string/gift_terms_condition"/>
</LinearLayout>
<Button
android:id="@+id/btn_send_gift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/gift_submit_btn"
android:layout_marginBottom="@dimen/margin_10"
android:layout_marginTop="@dimen/margin_20"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
MyTab2 xml :
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/margin_15"
android:layout_marginLeft="@dimen/margin_15"
android:layout_marginRight="@dimen/margin_15">
<include layout="@layout/voucher_common_layout"/>
<LinearLayout
android:id="@+id/terms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginRight="@dimen/margin_12"
android:orientation="horizontal"
android:gravity="center">
<CheckBox
android:id="@+id/buy_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_term_condition"
android:layout_marginLeft="@dimen/margin_5"
android:text="@string/gift_terms_condition"/>
</LinearLayout>
<Button
android:id="@+id/gift_buy_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/gift_submit_btn"
android:layout_marginTop="@dimen/margin_30"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
android android-layout android-scrollview
|
show 5 more comments
I can't figure out , why layout_weight is not working inside the ScrollView , when i am running this xml , i am getting imageview capturing the whole screen and below that i can see my tabs and the viewpager got hidden .
When i am giving the height in dp to all the linear layout below the ScrollView , i am getting my view perfectly ,why it's happening . i want my imageview to take 30% screen and tab/viewpager to take 70% of screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/gift_vouchr_header_img"
android:layout_weight="3"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="0dp"
android:orientation="vertical"
android:tag="sticky"
android:layout_weight="7"
android:adjustViewBounds="true"
android:layout_gravity="center"
>
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
When i remove weightsum and hardcoding the height then the view is working perfectly : below is my code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="@color/gift_vouchr_header_img"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="500dp"
android:orientation="vertical"
android:tag="sticky"
android:adjustViewBounds="true"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
MyTab1 xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_15"
android:layout_marginRight="@dimen/margin_15"
android:layout_marginTop="@dimen/margin_15"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_amount_footer_txt"
android:text="@string/validity"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/voucher_common_layout"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_title_txt"
android:layout_marginTop="@dimen/margin_26"
android:text="@string/receiver_detail"/>
<EditText
android:id="@+id/receiver_name"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:backgroundTint="@color/QuaternaryTextColor"
android:hint="@string/receiver_name"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_23"/>
<EditText
android:id="@+id/receiver_email"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:hint="@string/receiver_email"
android:inputType="textEmailAddress"
android:backgroundTint="@color/QuaternaryTextColor"
style="@style/giftEditetxtStyle"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_30"/>
<EditText
android:id="@+id/receiver_mobile"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:backgroundTint="@color/QuaternaryTextColor"
android:inputType="phone"
android:hint="@string/receiver_mobile"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_30"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginBottom="@dimen/margin_30"
android:layout_marginRight="@dimen/margin_12"
android:gravity="center"
android:orientation="horizontal">
<CheckBox
android:id="@+id/send_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_term_condition"
android:layout_marginLeft="@dimen/margin_5"
android:text="@string/gift_terms_condition"/>
</LinearLayout>
<Button
android:id="@+id/btn_send_gift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/gift_submit_btn"
android:layout_marginBottom="@dimen/margin_10"
android:layout_marginTop="@dimen/margin_20"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
MyTab2 xml :
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/margin_15"
android:layout_marginLeft="@dimen/margin_15"
android:layout_marginRight="@dimen/margin_15">
<include layout="@layout/voucher_common_layout"/>
<LinearLayout
android:id="@+id/terms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginRight="@dimen/margin_12"
android:orientation="horizontal"
android:gravity="center">
<CheckBox
android:id="@+id/buy_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_term_condition"
android:layout_marginLeft="@dimen/margin_5"
android:text="@string/gift_terms_condition"/>
</LinearLayout>
<Button
android:id="@+id/gift_buy_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/gift_submit_btn"
android:layout_marginTop="@dimen/margin_30"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
android android-layout android-scrollview
I guess you want that "Submit" Button near the bottom of the page, close to the navigation. if that is the case, you should write it as last sentence. My guess is that you should use a different type of layout, but I'm just guessing here.
– Jan
Nov 6 '18 at 12:07
what do you want? your button will be shown below.
– farhana
Nov 6 '18 at 12:17
yes i need submit button at the last , but i had put that button in the fragment , i don't need that button in the main layout , because the two tab has different type of button in shape and size, it's buttom of the layout itself , but when i scroll it keeps on scrolling and leaving extra space
– Amit Ranjan
Nov 6 '18 at 12:22
@farhana there is two tab each tab is having it's own layout , in each layout there is view which contains button at the end , the layout is perfect but when i am scrolling upward then the button goes up , what i need when user scroll then it's show only same height but it's showing me extra height , i am putting my xml in code for the view
– Amit Ranjan
Nov 6 '18 at 12:25
keep your button outside theScrollView
and take another view outside ScrollView` which will place both the view at their position then your button will not scroll with the content.
– farhana
Nov 6 '18 at 18:02
|
show 5 more comments
I can't figure out , why layout_weight is not working inside the ScrollView , when i am running this xml , i am getting imageview capturing the whole screen and below that i can see my tabs and the viewpager got hidden .
When i am giving the height in dp to all the linear layout below the ScrollView , i am getting my view perfectly ,why it's happening . i want my imageview to take 30% screen and tab/viewpager to take 70% of screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/gift_vouchr_header_img"
android:layout_weight="3"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="0dp"
android:orientation="vertical"
android:tag="sticky"
android:layout_weight="7"
android:adjustViewBounds="true"
android:layout_gravity="center"
>
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
When i remove weightsum and hardcoding the height then the view is working perfectly : below is my code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="@color/gift_vouchr_header_img"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="500dp"
android:orientation="vertical"
android:tag="sticky"
android:adjustViewBounds="true"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
MyTab1 xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_15"
android:layout_marginRight="@dimen/margin_15"
android:layout_marginTop="@dimen/margin_15"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_amount_footer_txt"
android:text="@string/validity"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/voucher_common_layout"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_title_txt"
android:layout_marginTop="@dimen/margin_26"
android:text="@string/receiver_detail"/>
<EditText
android:id="@+id/receiver_name"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:backgroundTint="@color/QuaternaryTextColor"
android:hint="@string/receiver_name"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_23"/>
<EditText
android:id="@+id/receiver_email"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:hint="@string/receiver_email"
android:inputType="textEmailAddress"
android:backgroundTint="@color/QuaternaryTextColor"
style="@style/giftEditetxtStyle"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_30"/>
<EditText
android:id="@+id/receiver_mobile"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:backgroundTint="@color/QuaternaryTextColor"
android:inputType="phone"
android:hint="@string/receiver_mobile"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_30"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginBottom="@dimen/margin_30"
android:layout_marginRight="@dimen/margin_12"
android:gravity="center"
android:orientation="horizontal">
<CheckBox
android:id="@+id/send_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_term_condition"
android:layout_marginLeft="@dimen/margin_5"
android:text="@string/gift_terms_condition"/>
</LinearLayout>
<Button
android:id="@+id/btn_send_gift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/gift_submit_btn"
android:layout_marginBottom="@dimen/margin_10"
android:layout_marginTop="@dimen/margin_20"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
MyTab2 xml :
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/margin_15"
android:layout_marginLeft="@dimen/margin_15"
android:layout_marginRight="@dimen/margin_15">
<include layout="@layout/voucher_common_layout"/>
<LinearLayout
android:id="@+id/terms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginRight="@dimen/margin_12"
android:orientation="horizontal"
android:gravity="center">
<CheckBox
android:id="@+id/buy_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_term_condition"
android:layout_marginLeft="@dimen/margin_5"
android:text="@string/gift_terms_condition"/>
</LinearLayout>
<Button
android:id="@+id/gift_buy_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/gift_submit_btn"
android:layout_marginTop="@dimen/margin_30"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
android android-layout android-scrollview
I can't figure out , why layout_weight is not working inside the ScrollView , when i am running this xml , i am getting imageview capturing the whole screen and below that i can see my tabs and the viewpager got hidden .
When i am giving the height in dp to all the linear layout below the ScrollView , i am getting my view perfectly ,why it's happening . i want my imageview to take 30% screen and tab/viewpager to take 70% of screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/gift_vouchr_header_img"
android:layout_weight="3"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="0dp"
android:orientation="vertical"
android:tag="sticky"
android:layout_weight="7"
android:adjustViewBounds="true"
android:layout_gravity="center"
>
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
When i remove weightsum and hardcoding the height then the view is working perfectly : below is my code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="@color/gift_vouchr_header_img"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="500dp"
android:orientation="vertical"
android:tag="sticky"
android:adjustViewBounds="true"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
MyTab1 xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_15"
android:layout_marginRight="@dimen/margin_15"
android:layout_marginTop="@dimen/margin_15"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_amount_footer_txt"
android:text="@string/validity"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/voucher_common_layout"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_title_txt"
android:layout_marginTop="@dimen/margin_26"
android:text="@string/receiver_detail"/>
<EditText
android:id="@+id/receiver_name"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:backgroundTint="@color/QuaternaryTextColor"
android:hint="@string/receiver_name"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_23"/>
<EditText
android:id="@+id/receiver_email"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:hint="@string/receiver_email"
android:inputType="textEmailAddress"
android:backgroundTint="@color/QuaternaryTextColor"
style="@style/giftEditetxtStyle"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_30"/>
<EditText
android:id="@+id/receiver_mobile"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_48"
android:backgroundTint="@color/QuaternaryTextColor"
android:inputType="phone"
android:hint="@string/receiver_mobile"
android:paddingLeft="@dimen/margin_2"
android:layout_marginTop="@dimen/margin_30"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginBottom="@dimen/margin_30"
android:layout_marginRight="@dimen/margin_12"
android:gravity="center"
android:orientation="horizontal">
<CheckBox
android:id="@+id/send_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_term_condition"
android:layout_marginLeft="@dimen/margin_5"
android:text="@string/gift_terms_condition"/>
</LinearLayout>
<Button
android:id="@+id/btn_send_gift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/gift_submit_btn"
android:layout_marginBottom="@dimen/margin_10"
android:layout_marginTop="@dimen/margin_20"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
MyTab2 xml :
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/margin_15"
android:layout_marginLeft="@dimen/margin_15"
android:layout_marginRight="@dimen/margin_15">
<include layout="@layout/voucher_common_layout"/>
<LinearLayout
android:id="@+id/terms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_40"
android:layout_marginRight="@dimen/margin_12"
android:orientation="horizontal"
android:gravity="center">
<CheckBox
android:id="@+id/buy_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/gift_term_condition"
android:layout_marginLeft="@dimen/margin_5"
android:text="@string/gift_terms_condition"/>
</LinearLayout>
<Button
android:id="@+id/gift_buy_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/gift_submit_btn"
android:layout_marginTop="@dimen/margin_30"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
android android-layout android-scrollview
android android-layout android-scrollview
edited Nov 12 '18 at 7:27
Amit Ranjan
asked Nov 6 '18 at 11:55
Amit RanjanAmit Ranjan
44
44
I guess you want that "Submit" Button near the bottom of the page, close to the navigation. if that is the case, you should write it as last sentence. My guess is that you should use a different type of layout, but I'm just guessing here.
– Jan
Nov 6 '18 at 12:07
what do you want? your button will be shown below.
– farhana
Nov 6 '18 at 12:17
yes i need submit button at the last , but i had put that button in the fragment , i don't need that button in the main layout , because the two tab has different type of button in shape and size, it's buttom of the layout itself , but when i scroll it keeps on scrolling and leaving extra space
– Amit Ranjan
Nov 6 '18 at 12:22
@farhana there is two tab each tab is having it's own layout , in each layout there is view which contains button at the end , the layout is perfect but when i am scrolling upward then the button goes up , what i need when user scroll then it's show only same height but it's showing me extra height , i am putting my xml in code for the view
– Amit Ranjan
Nov 6 '18 at 12:25
keep your button outside theScrollView
and take another view outside ScrollView` which will place both the view at their position then your button will not scroll with the content.
– farhana
Nov 6 '18 at 18:02
|
show 5 more comments
I guess you want that "Submit" Button near the bottom of the page, close to the navigation. if that is the case, you should write it as last sentence. My guess is that you should use a different type of layout, but I'm just guessing here.
– Jan
Nov 6 '18 at 12:07
what do you want? your button will be shown below.
– farhana
Nov 6 '18 at 12:17
yes i need submit button at the last , but i had put that button in the fragment , i don't need that button in the main layout , because the two tab has different type of button in shape and size, it's buttom of the layout itself , but when i scroll it keeps on scrolling and leaving extra space
– Amit Ranjan
Nov 6 '18 at 12:22
@farhana there is two tab each tab is having it's own layout , in each layout there is view which contains button at the end , the layout is perfect but when i am scrolling upward then the button goes up , what i need when user scroll then it's show only same height but it's showing me extra height , i am putting my xml in code for the view
– Amit Ranjan
Nov 6 '18 at 12:25
keep your button outside theScrollView
and take another view outside ScrollView` which will place both the view at their position then your button will not scroll with the content.
– farhana
Nov 6 '18 at 18:02
I guess you want that "Submit" Button near the bottom of the page, close to the navigation. if that is the case, you should write it as last sentence. My guess is that you should use a different type of layout, but I'm just guessing here.
– Jan
Nov 6 '18 at 12:07
I guess you want that "Submit" Button near the bottom of the page, close to the navigation. if that is the case, you should write it as last sentence. My guess is that you should use a different type of layout, but I'm just guessing here.
– Jan
Nov 6 '18 at 12:07
what do you want? your button will be shown below.
– farhana
Nov 6 '18 at 12:17
what do you want? your button will be shown below.
– farhana
Nov 6 '18 at 12:17
yes i need submit button at the last , but i had put that button in the fragment , i don't need that button in the main layout , because the two tab has different type of button in shape and size, it's buttom of the layout itself , but when i scroll it keeps on scrolling and leaving extra space
– Amit Ranjan
Nov 6 '18 at 12:22
yes i need submit button at the last , but i had put that button in the fragment , i don't need that button in the main layout , because the two tab has different type of button in shape and size, it's buttom of the layout itself , but when i scroll it keeps on scrolling and leaving extra space
– Amit Ranjan
Nov 6 '18 at 12:22
@farhana there is two tab each tab is having it's own layout , in each layout there is view which contains button at the end , the layout is perfect but when i am scrolling upward then the button goes up , what i need when user scroll then it's show only same height but it's showing me extra height , i am putting my xml in code for the view
– Amit Ranjan
Nov 6 '18 at 12:25
@farhana there is two tab each tab is having it's own layout , in each layout there is view which contains button at the end , the layout is perfect but when i am scrolling upward then the button goes up , what i need when user scroll then it's show only same height but it's showing me extra height , i am putting my xml in code for the view
– Amit Ranjan
Nov 6 '18 at 12:25
keep your button outside the
ScrollView
and take another view outside ScrollView` which will place both the view at their position then your button will not scroll with the content.– farhana
Nov 6 '18 at 18:02
keep your button outside the
ScrollView
and take another view outside ScrollView` which will place both the view at their position then your button will not scroll with the content.– farhana
Nov 6 '18 at 18:02
|
show 5 more comments
1 Answer
1
active
oldest
votes
None of the above solution worked for me , i found the solution myself like this : hope it will help someone : No changes in the tab code . In the main xml , i have done like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/childImg_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gift_vouchr_header_img"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="sticky"
android:adjustViewBounds="true"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
app:tabMode="fixed"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
Here comes the important part : Pragmatically set the height of the child layout :D
private void setViewPagerandImageViewHeight()
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int heightOfScreen = displayMetrics.heightPixels;
child_img_ll.getLayoutParams().height= (int) (heightOfScreen*.30);// set imageview linearlayout to capture 30% of screen
viewpager_ll.getLayoutParams().height=heightOfScreen;//while scrolling set the viewpager height to maximum ,intially it capture 70% of screen
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53171409%2flayout-weight-is-not-working-inside-scrollview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
None of the above solution worked for me , i found the solution myself like this : hope it will help someone : No changes in the tab code . In the main xml , i have done like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/childImg_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gift_vouchr_header_img"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="sticky"
android:adjustViewBounds="true"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
app:tabMode="fixed"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
Here comes the important part : Pragmatically set the height of the child layout :D
private void setViewPagerandImageViewHeight()
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int heightOfScreen = displayMetrics.heightPixels;
child_img_ll.getLayoutParams().height= (int) (heightOfScreen*.30);// set imageview linearlayout to capture 30% of screen
viewpager_ll.getLayoutParams().height=heightOfScreen;//while scrolling set the viewpager height to maximum ,intially it capture 70% of screen
add a comment |
None of the above solution worked for me , i found the solution myself like this : hope it will help someone : No changes in the tab code . In the main xml , i have done like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/childImg_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gift_vouchr_header_img"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="sticky"
android:adjustViewBounds="true"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
app:tabMode="fixed"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
Here comes the important part : Pragmatically set the height of the child layout :D
private void setViewPagerandImageViewHeight()
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int heightOfScreen = displayMetrics.heightPixels;
child_img_ll.getLayoutParams().height= (int) (heightOfScreen*.30);// set imageview linearlayout to capture 30% of screen
viewpager_ll.getLayoutParams().height=heightOfScreen;//while scrolling set the viewpager height to maximum ,intially it capture 70% of screen
add a comment |
None of the above solution worked for me , i found the solution myself like this : hope it will help someone : No changes in the tab code . In the main xml , i have done like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/childImg_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gift_vouchr_header_img"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="sticky"
android:adjustViewBounds="true"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
app:tabMode="fixed"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
Here comes the important part : Pragmatically set the height of the child layout :D
private void setViewPagerandImageViewHeight()
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int heightOfScreen = displayMetrics.heightPixels;
child_img_ll.getLayoutParams().height= (int) (heightOfScreen*.30);// set imageview linearlayout to capture 30% of screen
viewpager_ll.getLayoutParams().height=heightOfScreen;//while scrolling set the viewpager height to maximum ,intially it capture 70% of screen
None of the above solution worked for me , i found the solution myself like this : hope it will help someone : No changes in the tab code . In the main xml , i have done like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/childImg_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gift_vouchr_header_img"
android:adjustViewBounds="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageview_gift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/splash"/>
</LinearLayout>
<LinearLayout
android:id="@+id/viewpager_ll"
android:layout_width="match_parent"
android:background="@color/lvb_divider_color"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="sticky"
android:adjustViewBounds="true"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="@+id/common_tablayout"
style="@style/VoucherTabLayoutStyle"
android:layout_width="match_parent"
app:tabGravity="fill"
app:tabMode="fixed"
android:layout_height="@dimen/margin_48">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/common_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
</LinearLayout>
Here comes the important part : Pragmatically set the height of the child layout :D
private void setViewPagerandImageViewHeight()
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int heightOfScreen = displayMetrics.heightPixels;
child_img_ll.getLayoutParams().height= (int) (heightOfScreen*.30);// set imageview linearlayout to capture 30% of screen
viewpager_ll.getLayoutParams().height=heightOfScreen;//while scrolling set the viewpager height to maximum ,intially it capture 70% of screen
answered Nov 12 '18 at 11:00
Amit RanjanAmit Ranjan
44
44
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53171409%2flayout-weight-is-not-working-inside-scrollview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I guess you want that "Submit" Button near the bottom of the page, close to the navigation. if that is the case, you should write it as last sentence. My guess is that you should use a different type of layout, but I'm just guessing here.
– Jan
Nov 6 '18 at 12:07
what do you want? your button will be shown below.
– farhana
Nov 6 '18 at 12:17
yes i need submit button at the last , but i had put that button in the fragment , i don't need that button in the main layout , because the two tab has different type of button in shape and size, it's buttom of the layout itself , but when i scroll it keeps on scrolling and leaving extra space
– Amit Ranjan
Nov 6 '18 at 12:22
@farhana there is two tab each tab is having it's own layout , in each layout there is view which contains button at the end , the layout is perfect but when i am scrolling upward then the button goes up , what i need when user scroll then it's show only same height but it's showing me extra height , i am putting my xml in code for the view
– Amit Ranjan
Nov 6 '18 at 12:25
keep your button outside the
ScrollView
and take another view outside ScrollView` which will place both the view at their position then your button will not scroll with the content.– farhana
Nov 6 '18 at 18:02