Image
I have a Toolbar with an ImageView inside. My problem is that this image is not positioned at the center of my Toolbar on tablets(it works fine on mobile devices). What can I do? Gravity doesn't work and I can't use a relative layout. There is an image on top showing my problem.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:design="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="mfceo.project.matiasnagore.powerlist.MainActivity">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="#+id/mainToolbar"
android:background="#fafafa"
android:titleTextColor="#ffffff"
android:layout_gravity="top">
<ImageView
android:id="#+id/imagePowerlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/powerlist"
android:scaleType="centerInside"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="55dp" />
</android.support.v7.widget.Toolbar>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#drawable/shadow_top"/>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ffffff">
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#drawable/shadow"/>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
design:menu="#menu/bottom_nav_items"
design:itemIconTint="#drawable/selector"
design:itemTextColor="#drawable/selector"
android:background="#FFFAFAFA" />
</LinearLayout>
You need to add android:layout_gravity="top|center_horizontal" into your ImageView and remove paddings:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:design="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="mfceo.project.matiasnagore.powerlist.MainActivity"><android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="#+id/mainToolbar"
android:background="#fafafa"
android:titleTextColor="#ffffff"
android:layout_gravity="top">
<ImageView
android:id="#+id/imagePowerlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/powerlist"
android:scaleType="centerInside"
android:layout_gravity="top|center_horizontal"/>
</android.support.v7.widget.Toolbar>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#drawable/shadow_top"/>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ffffff">
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#drawable/shadow"/>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
design:menu="#menu/bottom_nav_items"
design:itemIconTint="#drawable/selector"
design:itemTextColor="#drawable/selector"
android:background="#FFFAFAFA" /></LinearLayout>
Related
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
}
I've got a Webview and a Toolbar. Without the Toolbar, the Webview is completely scollable, but when I add the Toolbar the the Webview doesn't scroll anymore. I've tried NestedScrollView but it just doesn't work. Here's the layout of my activity:
<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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
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="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="100">
<ImageButton
android:id="#+id/homeButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:contentDescription="#string/home"
app:srcCompat="#drawable/ic_home" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="60"
android:gravity="center"
android:text="#string/app_name"
android:textSize="24sp"
android:textStyle="bold"
app:fontFamily="Sans Serif" />
<ImageButton
android:id="#+id/menuButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:contentDescription="#string/menu"
app:srcCompat="#drawable/ic_menu_black_24dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:id="#+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MailActivity">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
The Java code for the Toolbar simply creates the menu and the home button, while the webview simply loads an url (javascript is enabled).
Thanks a lot for your help!
<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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="100">
<ImageButton
android:id="#+id/homeButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:contentDescription="#string/home"
app:srcCompat="#drawable/ic_home" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="60"
android:gravity="center"
android:text="#string/app_name"
android:textSize="24sp"
android:textStyle="bold"
app:fontFamily="Sans Serif" />
<ImageButton
android:id="#+id/menuButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:contentDescription="#string/menu"
app:srcCompat="#drawable/ic_menu_black_24dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
You have to move Relative layout outside of the Appbar.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="100">
<ImageButton
android:id="#+id/homeButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:contentDescription="#string/home"
app:srcCompat="#drawable/ic_home" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="60"
android:gravity="center"
android:text="#string/app_name"
android:textSize="24sp"
android:textStyle="bold"
app:fontFamily="Sans Serif" />
<ImageButton
android:id="#+id/menuButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:contentDescription="#string/menu"
app:srcCompat="#drawable/ic_menu_black_24dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</LinearLayout>
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 this problem to accommodate my floating button, and I do not understand why it does not work.
I would appreciate your response since I can not find the reason why this is happening, one more detail when scrolling or reloading the fragment some of the floating buttons will be accommodated.
And sorry for my English.
<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="wrap_content"
android:background="#color/colorBackground"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.CardView
android:id="#+id/mRequestCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="100dp"
android:orientation="horizontal"
app:cardBackgroundColor="#color/colorWhite"
app:cardCornerRadius="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="#+id/vDivisor"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorGreen" />
...
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="#dimen/fab_margin"
android:backgroundTint="#color/colorPurple"
android:scaleType="centerCrop"
android:src="#drawable/ic_route_direction"
app:layout_anchor="#id/mRequestCard"
app:layout_anchorGravity="right|end|bottom" />
</android.support.design.widget.CoordinatorLayout>
And this is my RecyclerView Which is inflated in a fragment
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.HistorialFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/mRecyclerRequest"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</FrameLayout>
And this is my fragment, where I show the RecyclerView
<FrameLayout 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:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.test.MainActivity"
tools:showIn="#layout/app_bar_main">
</FrameLayout>
you should try RelativeLayout like this
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorBlack"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="#dimen/activity_corner"
android:layout_marginBottom="#dimen/activity_margin">
<!--your cardview item here-->
</android.support.v7.widget.CardView>
</RelativeLayout>
for your RecyclerView item
Check if this helps you:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#color/colorPrimary"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.CardView
android:id="#+id/mRequestCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="100dp"
android:orientation="horizontal"
app:cardBackgroundColor="#color/colorWhite"
app:cardCornerRadius="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="#+id/vDivisor"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorGreen" />
...
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:backgroundTint="#color/colorAccent"
android:scaleType="centerCrop"
android:src="#drawable/ic_launcher"
app:layout_anchor="#id/mRequestCard"
app:layout_anchorGravity="right|end|bottom" />
</RelativeLayout>
try this use RelativeLayout and make your FloatingActionButton property android:layout_alignParentBottom="true" and
android:layout_alignParentRight="true" like below code
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorBlack"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="#dimen/activity_corner"
android:layout_marginBottom="#dimen/activity_margin">
</android.support.v7.widget.CardView>
</RelativeLayout>
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>