Reputation: 465
I have this activity in my application:
I can't set the second CardView correctly. I need to use all free space between the card and the buttons at the end I tried everything, match_parent, alignment... but nothing.
This is the code:
<?xml version="1.0" encoding="utf-8"?>
android:id="@+id/left_drawer_activity_customers_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/right_drawer_activity_customers_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sfondo_sfumato"
>
<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:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
android:id="@+id/appbar_activity_customers_details">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_activity_customers_details"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="@+id/scrollDetails"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="55dp"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
card_view:cardCornerRadius="5dp"
card_view:cardBackgroundColor="#FFFFFF"
card_view:cardElevation="7dp"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:weightSum="1"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title_customers_details"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="Title"
android:textSize="20sp"
android:typeface="serif"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:textSize="16sp"
android:layout_below="@id/title_customers_details"
android:id="@+id/customersdetails_nome"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_below="@id/customersdetails_nome"
android:text="New Text"
android:textSize="16sp"
android:id="@+id/customersdetails_città"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_below="@id/customersdetails_città"
android:textSize="16sp"
android:id="@+id/customersdetails_indirizzo"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_below="@id/customersdetails_indirizzo"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:textSize="16sp"
android:id="@+id/customersdetails_provincia"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_below="@id/customersdetails_provincia"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:textSize="16sp"
android:id="@+id/customersdetails_phone"
android:autoLink="phone"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<!-- Fragment Container -->
<!--<LinearLayout-->
<!--android:id="@+id/fragment_container"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical"-->
<!-->-->
<!--</LinearLayout>-->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Apri ticket"
android:backgroundTint="#F44336"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
card_view:cardCornerRadius="5dp"
card_view:cardBackgroundColor="#FFFFFF"
card_view:cardElevation="7dp"
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="12dp" >
<TextView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test"/>
</RelativeLayout>
</ScrollView>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center|bottom"
>
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ticket"
android:backgroundTint="#F44336"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contratti"
android:backgroundTint="#F44336"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contatti"
android:backgroundTint="#F44336"
android:textColor="#FFFFFF"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view_right_activity_customers_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_right_customer"
app:menu="@menu/menu_right_customer" />
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view_left_activity_customers_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/menu_left_drawer" />
Do I need to insert all my layout in another linear_layout?
Can someone help me please?
Edit I used 200dp in layout_height just for take the screenshot
Upvotes: 0
Views: 425
Reputation: 3455
ScrollView
with id scrollDetails
from your layout. Wrap the CardView
& LinearLayout
holding those 3 buttons at bottom into a RelativeLayout
like below.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_above="@+id/linearButtonLayout"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
card_view:cardCornerRadius="5dp"
card_view:cardBackgroundColor="#FFFFFF"
card_view:cardElevation="7dp">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="12dp" >
<TextView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/big_string"/>
</RelativeLayout>
</ScrollView>
</android.support.v7.widget.CardView>
<LinearLayout
android:id="@+id/linearButtonLayout"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center|bottom">
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ticket"
android:backgroundTint="#F44336"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contratti"
android:backgroundTint="#F44336"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contatti"
android:backgroundTint="#F44336"
android:textColor="#FFFFFF"/>
</LinearLayout>
</RelativeLayout>
Upvotes: 1
Reputation: 66
If you wants to keep all of your scrolling, Change in your second CardView layout_height to 0dp and add layout_weight like below:
android:layout_height="0dp"
android:layout_weight="1"
Change your bottom LinearLayout height to wrap_content like this
android:layout_height="wrap_content"
I hope your problem is solved.
Upvotes: 0
Reputation: 71
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
card_view:cardBackgroundColor="#FFFFFF"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="7dp">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/title_customers_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="Title"
android:textSize="20sp"
android:typeface="serif" />
<TextView
android:id="@+id/customersdetails_nome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title_customers_details"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:text="New Text"
android:textSize="16sp" />
<TextView
android:id="@+id/customersdetails_città"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/customersdetails_nome"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:text="New Text"
android:textSize="16sp" />
<TextView
android:id="@+id/customersdetails_indirizzo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/customersdetails_città"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:text="New Text"
android:textSize="16sp" />
<TextView
android:id="@+id/customersdetails_provincia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/customersdetails_indirizzo"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:text="New Text"
android:textSize="16sp" />
<TextView
android:id="@+id/customersdetails_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/customersdetails_provincia"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:autoLink="phone"
android:text="New Text"
android:textSize="16sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:backgroundTint="#F44336"
android:text="Apri ticket"
android:textColor="#FFFFFF" />
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical"
card_view:cardBackgroundColor="#FFFFFF"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="7dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test" />
</ScrollView>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center|bottom"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#F44336"
android:text="Ticket"
android:textColor="#FFFFFF" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#F44336"
android:text="Contratti"
android:textColor="#FFFFFF" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#F44336"
android:text="Contatti"
android:textColor="#FFFFFF" />
</LinearLayout>
Upvotes: 0
Reputation: 1562
You can do this -
Assign top LinearLayout (after ScrollView one) a wieghtSum 10 and then assign first cardView a layout_wieght = 3 and to button below it a layout_wieght = 1 and cardView below it a layout_wieght = 4 and LinearLayout below a layout_wieght = 2 .
Try it.
Upvotes: 0