LinearLayout 不适合
LinearLayout doesn't fit
我的应用程序中有这个 activity:
我无法正确设置第二个 CardView。我需要在卡片和最后的按钮之间使用所有免费 space
我什么都试过了,match_parent,对齐...但是什么都没有。
这是代码:
<?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" />
我是否需要将所有布局插入另一个 linear_layout?
有人可以帮我吗?
编辑
我在 layout_height 中使用了 200dp 只是为了截图
你可以做到 -
为顶部 LinearLayout(在 ScrollView 之后)分配一个 wieghtSum 10,然后为第一个 cardView 分配一个 layout_wieght = 3 并为其下方的按钮分配一个 layout_wieght = 1 并为其下方的 cardView 分配一个 layout_wieght = 4 和下面的 LinearLayout layout_wieght = 2 .
试试吧。
<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>
如果您想保留所有滚动,请将第二个 CardView layout_height 更改为 0dp 并添加 layout_weight,如下所示:
android:layout_height="0dp"
android:layout_weight="1"
像这样将您的底部 LinearLayout 高度更改为 wrap_content
android:layout_height="wrap_content"
希望你的问题得到解决
- 从布局中删除 ID 为
scrollDetails
的 ScrollView
。
将底部的 CardView
和 LinearLayout
按住这 3 个按钮包裹成如下所示的 RelativeLayout
。
<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>
我的应用程序中有这个 activity:
我无法正确设置第二个 CardView。我需要在卡片和最后的按钮之间使用所有免费 space 我什么都试过了,match_parent,对齐...但是什么都没有。
这是代码:
<?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" />
我是否需要将所有布局插入另一个 linear_layout?
有人可以帮我吗?
编辑 我在 layout_height 中使用了 200dp 只是为了截图
你可以做到 -
为顶部 LinearLayout(在 ScrollView 之后)分配一个 wieghtSum 10,然后为第一个 cardView 分配一个 layout_wieght = 3 并为其下方的按钮分配一个 layout_wieght = 1 并为其下方的 cardView 分配一个 layout_wieght = 4 和下面的 LinearLayout layout_wieght = 2 .
试试吧。
<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>
如果您想保留所有滚动,请将第二个 CardView layout_height 更改为 0dp 并添加 layout_weight,如下所示:
android:layout_height="0dp"
android:layout_weight="1"
像这样将您的底部 LinearLayout 高度更改为 wrap_content
android:layout_height="wrap_content"
希望你的问题得到解决
- 从布局中删除 ID 为
scrollDetails
的ScrollView
。 将底部的
CardView
和LinearLayout
按住这 3 个按钮包裹成如下所示的RelativeLayout
。<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>