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>
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
}
Related
I want to divide my screen into 3 vertically equal parts and add an ImageView to the top part. When I add the image, the parts won't be equal.
It can not be changed using layout weight.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
android:orientation="vertical"
tools:showIn="#layout/app_bar_main"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/logo1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</LinearLayout>
You need to set android:layout_height="0dp" in all LinearLayout like :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ff0000">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#00ff00">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#0000ff">
</LinearLayout>
OUTPUT
I want my viewpager display fragment in the full screen.It is not displaying only in the half of the screen.I am stuck with this issue from past two days.So please help me to come out of this issue.Thanks in advance.
This is my activity code named activity_subcategory.xml -
<LinearLayout
android:id="#+id/main_layout"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:navigationIcon="#drawable/ic_arrow_back"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<!-- our tablayout to display tabs -->
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:layout_gravity="center_horizontal"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/buttoncolor"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="#color/buttoncolor"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<!-- View pager to swipe views -->
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
This is my Fragment code named singlesubcategory.xml -
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="10dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<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="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imgcat"
android:layout_width="100dp"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:layout_margin="5dp"
android:src="#drawable/laundry1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtcat"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:weightSum="10"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_weight="7"
android:layout_marginRight="2dp"
android:text="₹ 30"
android:gravity="center"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/ic_addtocart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:layout_marginRight="2dp"
android:text="0"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/ic_removecart"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
See this image. i want that card display in full width of screen.
This is my recyclerview code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rcv"></android.support.v7.widget.RecyclerView>
</LinearLayout>
Change viewpager height
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
in your xml activity_subcategory.xml
change parent Linear layout
<LinearLayout
android:id="#+id/main_layout"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent">
change height to fill parent.
Use this code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/rcv"
android:layout_gravity="center"
android:foregroundGravity="center">
</android.support.v7.widget.RecyclerView>
for view pager use fill parent
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
I have one Activity and two Fragments. I want to put them in Activity one under another and I need that height both of them will be the same. But when I try, always fragment with webView become smaller, then another. And I don't want to set height of WebView in dp or px.
Here is my xml code.
activity_object_detail_info.xml
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/appBar"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="24dp"
android:layout_height="24dp"
android:id="#+id/back_buttonObject"
android:background="#drawable/ic_arrow_back_white_24dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity = "center_vertical|center_horizontal"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/object"
android:textColor="#color/white"
android:id="#+id/toolbar_titleObject"
android:textSize="24dp" />
</LinearLayout>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/arrowDownA"
android:src="#drawable/arrow_down"
android:layout_marginRight="10dp"/>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/arrowUpA"
android:src="#drawable/arrow_up"
android:layout_marginRight="5dp"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/objectMap"
android:layout_weight="1"/>
<FrameLayout
android:id="#+id/objectContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
fragment_map_object.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/webViewLL"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webviewMapOdject"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:id="#+id/cleanLayersObject"
style="?android:attr/buttonStyleSmall"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/clean"
android:singleLine="false"
android:layout_gravity="end"
android:layout_marginTop="70dp"
android:layout_marginRight="10dp"/>
</FrameLayout>
</LinearLayout>
</LinearLayout>
fragment_content_object.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.TabLayout
android:id="#+id/result_tabs"
android:background="#color/colorPrimary"
app:tabSelectedTextColor="#color/white"
app:tabIndicatorColor="#color/white"
app:tabTextColor="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>
Can you help, please?
Please update below code in activity_object_detail_info.xml file.
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/objectMap"
android:layout_weight="1"/>
<FrameLayout
android:id="#+id/objectContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
I have a TabLayout. In the MainActivity where I set the TabLayout I also have three buttons and a banner on bottom (so those buttons and banner are on front of the the tablayout). What I want to do is place an ImageView exactly between the button/banner and the tab. How can I achieve this?
Here is a picture of the layout, I want the view exactly in center between buttons and layout.
Code main_activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.tomhogenkamp.NeonDiscoLight.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
<LinearLayout
android:layout_above="#id/adView"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="settings"
android:id="#+id/setting"/>
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="start"
android:id="#+id/start"/>
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="rate"
android:id="#+id/rate"/>
</LinearLayout>
</RelativeLayout>
and code for fragment:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/viewStrobe"/>
<ImageView
android:layout_above="#+id/linearLayout"
android:id="#+id/imageViewStroboscope"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:adjustViewBounds="true"/>
</RelativeLayout>
Why the linear layout does not fill the whole screen?
As you can see I am using match parent in the linear layout.
If I delete the Scrollbar nothing changes. The button is not at the bottom of the screen.
main_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
tools:context="com.sarahp.demo.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout ----------> HERE
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textview_demo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="32dp"
android:layout_marginTop="32dp"
android:text="#string/demo"
android:textSize="42dp"/>
<RelativeLayout
android:id="#+id/fragment_container_a"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="#+id/fragment_container_b"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/transparent"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
F A is the fragment part.
Give android:fillViewport="true" to your ScrollView.
Your xml will looks like below. Main_Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
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">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Test Demo"
android:textStyle="bold"
android:gravity="center"/>
<RelativeLayout
android:id="#+id/fragment1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="#drawable/border_image">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center"
android:text="Test text Fragement1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/fragment2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center"
android:text="Test text Fragement2" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Remove the relative layout
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textview_demo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="32dp"
android:layout_marginTop="32dp"
android:text="#string/demo"
android:textSize="42dp"/>
<RelativeLayout
android:id="#+id/fragment_container_a"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="#+id/fragment_container_b"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/transparent"/>
</LinearLayout>
</ScrollView>