【发布时间】:2017-02-07 07:08:22
【问题描述】:
实际上我必须创建一个类似于下面的屏幕截图的 xml 布局,并且我知道线性布局中有两个 cardView 具有权重
但是任何人都可以检查我的代码并引导我走上正确的道路吗... xml代码:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="@dimen/padding_top_bottom">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.6"
>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/cardViewbackground">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/icon_btw_margin"
android:layout_marginLeft="@dimen/padding"
android:src="@drawable/service_provide_box_icon"
android:layout_marginTop="@dimen/padding"
android:layout_marginEnd="@dimen/icon_btw_padding"
android:layout_marginRight="@dimen/icon_btw_padding" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginStart="30dp"
android:layout_marginLeft="@dimen/icon_btw_padding"
android:text="@string/testAddress"
android:textColor="@color/buttonbackground"
android:layout_marginEnd="@dimen/icon_btw_padding"
android:layout_marginRight="@dimen/icon_btw_padding"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.7"
android:layout_marginStart="@dimen/padding_top_bottom"
android:layout_marginLeft="@dimen/padding_top_bottom"
>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
app:cardBackgroundColor="@color/cardViewbackground">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/car_services_icon_one"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
/>
</android.support.v7.widget.CardView><android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
app:cardBackgroundColor="@color/cardViewbackground"
android:layout_marginStart="6dp"
android:layout_marginLeft="@dimen/icon_btw_margin"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/car_services_icon_three"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="0sp">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.6"
>
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/cardViewbackground">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/icon_btw_margin"
android:layout_marginLeft="@dimen/padding"
android:src="@drawable/mechanics_available_icon"
android:layout_gravity="top"
android:layout_marginTop="@dimen/padding"
android:layout_marginEnd="@dimen/icon_btw_padding"
android:layout_marginRight="@dimen/icon_btw_padding" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginStart="30dp"
android:layout_marginLeft="@dimen/icon_btw_padding"
android:paddingTop="2dp"
android:text="@string/testMechanics"
android:textColor="@color/colorAccent"
android:layout_marginEnd="@dimen/icon_btw_padding"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/icon_btw_padding"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.7"
android:layout_marginStart="@dimen/padding_top_bottom"
android:layout_marginLeft="@dimen/padding_top_bottom"
>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
app:cardBackgroundColor="@color/cardViewbackground">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/car_services_iconfour"
android:layout_marginLeft="2dp"
android:paddingTop="1sp"
android:layout_marginRight="2dp"
/>
</android.support.v7.widget.CardView><android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
app:cardBackgroundColor="@color/cardViewbackground"
android:layout_marginStart="6dp"
android:layout_marginLeft="@dimen/icon_btw_margin"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/car_services_icon_two"
android:layout_marginLeft="2dp"
android:paddingTop="1sp"
android:layout_marginRight="2dp"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="0sp">
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/cardViewbackground">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/icon_btw_margin"
android:layout_marginLeft="@dimen/padding"
android:src="@drawable/mechanics_available_icon"
android:layout_gravity="top"
android:layout_marginTop="@dimen/padding"
android:layout_marginEnd="@dimen/icon_btw_padding"
android:layout_marginRight="@dimen/icon_btw_padding" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginStart="30dp"
android:layout_marginLeft="@dimen/icon_btw_padding"
android:paddingTop="2dp"
android:text="@string/testMechanics"
android:textColor="@color/colorAccent"
android:layout_marginEnd="@dimen/icon_btw_padding"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/icon_btw_padding"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
【问题讨论】:
-
不,你在做什么很容易通过 xml 来制作
-
fill_parent 也已弃用
-
好的,我将使用 wrap_content 而不是 fil_parent 你能告诉我简单的方法
-
匹配父级应替换为fill_parent
-
cardview 也应该只有直接子级\
标签: android xml android-layout android-linearlayout android-relativelayout