实际上我必须创建一个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>
答案 0 :(得分:1)
使用此XML。可能对你的工作有帮助..
<?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="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5sp"
android:weightSum="4">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
app:cardElevation="4dp"
app:cardUseCompatPadding="false"
app:cardBackgroundColor="#555555">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10sp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#124688"
android:drawableStart="@drawable/yourimage"
android:text="500 west and avenue suite 5A"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:gravity="center_vertical"
android:drawableStart="@drawable/mechanic image"
android:text="12 Mechanics availabe"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:gravity="center_vertical"
android:drawableStart="@drawable/watchimage"
android:text="9:00AM to 11:00PM"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.5"
android:scaleY="0.5"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
app:cardElevation="4dp"
android:layout_weight="1"
app:cardUseCompatPadding="false"
app:cardBackgroundColor="#555555">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/image1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/image2"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/image3"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/image4"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>