我在我的应用程序中有这个活动:
我无法正确设置第二个CardView。我需要在卡片和最后的按钮之间使用所有可用空间 我尝试了所有东西,match_parent,alignment ......但没有。
这是代码:
<?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只是为了截取屏幕截图
答案 0 :(得分:1)
ScrollView
的{{1}}。 包裹scrollDetails
&amp; CardView
将底部的3个按钮放在LinearLayout
下方。
RelativeLayout
答案 1 :(得分:0)
你可以这样做 -
将顶部的LinearLayout(在ScrollView之后)分配给wieghtSum 10,然后将第一个cardView分配给layout_wieght = 3并在其下面的按钮上分配layout_wieght = 1,在它下面的cardView中,layout_wieght = 4,在layout_wieght = 2下面的LinearLayout。
试试吧。
答案 2 :(得分:0)
<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>
答案 3 :(得分:0)
如果您想保留所有滚动,请将第二个CardView layout_height更改为0dp并添加如下所示的layout_weight:
android:layout_height="0dp"
android:layout_weight="1"
将您的底部LinearLayout高度更改为wrap_content,如下所示
android:layout_height="wrap_content"
我希望你的问题得到解决。