xml 中的 cardView 图标和名称对齐问题
cardView icon and name alignment issue in xml
我想在 cardview 中设置带有名称的图标。但是无法做到这一点。
使用此 xml 后对齐不正确。
应该是这样的图
activity_home
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<ImageView
android:id="@+id/test_image"
android:src="@drawable/test"
android:layout_width="match_parent"
android:layout_height="240dp"
android:scaleType="fitXY" />
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_gravity="center"
android:layout_margin="@dimen/card_margin"
android:elevation="3dp"
card_view:cardCornerRadius="@dimen/card_album_radius">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/location"
android:src="@drawable/location"
android:layout_width="80dp"
android:layout_height="100dp"
android:paddingLeft="20dp"
android:paddingTop="30dp"
android:text="Location" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:layout_below="@+id/location"
android:text="Location"
android:textSize="15dp"
android:textColor="#01458e"
android:textStyle="bold"
/>
<ImageView
android:id="@+id/deals"
android:src="@drawable/deals"
android:layout_width="80dp"
android:layout_height="100dp"
android:paddingLeft="40dp"
android:layout_toRightOf="@+id/location"
android:text="Deals"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="40dp"
android:paddingTop="10dp"
android:layout_toRightOf="@+id/location"
android:layout_below="@+id/deals"
android:text="Deals"
android:textSize="15dp"
android:textColor="#01458e"
android:textStyle="bold" />
<ImageView
android:id="@+id/cuisine"
android:src="@drawable/cuisine"
android:layout_width="60dp"
android:layout_height="80dp"
android:paddingTop="10dp"
android:paddingLeft="40dp"
android:layout_toRightOf="@+id/deals"
android:text="Cuisine"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/cuisine"
android:layout_below="@+id/cuisine"
android:text="Cuisine"
android:textSize="15dp"
android:textColor="#01458e"
android:textStyle="bold" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我在使用下面的类似图片后得到了
用这个 xml 代替你的 ...............
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<ImageView
android:id="@+id/test_image"
android:src="@drawable/test"
android:layout_width="match_parent"
android:layout_height="240dp"
android:scaleType="fitXY" />
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_gravity="center"
android:layout_margin="@dimen/card_margin"
android:elevation="3dp"
card_view:cardCornerRadius="@dimen/card_album_radius">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/location"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/whatsapp"
android:text="Location" />
<ImageView
android:id="@+id/deals"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/whatsapp"
android:text="Deals"/>
<ImageView
android:id="@+id/lastimage"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/whatsapp"
android:text="Deals"/>
<ImageView
android:id="@+id/cuisine"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/whatsapp"
android:text="Cuisine" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Location"
android:gravity="center"
android:textColor="#01458e"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Deals"
android:gravity="center"
android:textColor="#01458e"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Cuisine"
android:textColor="#01458e"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="LastText"
android:textColor="#01458e"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
注意:- 根据您的项目更改文本和图像....
你的图片看起来像这些......
享受编码......
给你。根据您的项目更改图像。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/test_image"
android:layout_width="match_parent"
android:layout_height="240dp"
android:scaleType="fitXY"
android:src="@drawable/bg_big" />
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:elevation="3dp"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/ic_eye" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Explore"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/location"
android:tint="@color/colorOrange" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Location"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/location"
android:tint="@color/colorOrange" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Deals"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/location"
android:tint="@color/colorOrange" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Cusine"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/car"
android:tint="@color/colorOrange" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Dive-in"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
看起来像这样:
在您的布局中,重新更正语法,其中 id=cusine,图像应为 b
width=80 and height=100.
我想在 cardview 中设置带有名称的图标。但是无法做到这一点。
使用此 xml 后对齐不正确。
应该是这样的图
activity_home
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<ImageView
android:id="@+id/test_image"
android:src="@drawable/test"
android:layout_width="match_parent"
android:layout_height="240dp"
android:scaleType="fitXY" />
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_gravity="center"
android:layout_margin="@dimen/card_margin"
android:elevation="3dp"
card_view:cardCornerRadius="@dimen/card_album_radius">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/location"
android:src="@drawable/location"
android:layout_width="80dp"
android:layout_height="100dp"
android:paddingLeft="20dp"
android:paddingTop="30dp"
android:text="Location" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:layout_below="@+id/location"
android:text="Location"
android:textSize="15dp"
android:textColor="#01458e"
android:textStyle="bold"
/>
<ImageView
android:id="@+id/deals"
android:src="@drawable/deals"
android:layout_width="80dp"
android:layout_height="100dp"
android:paddingLeft="40dp"
android:layout_toRightOf="@+id/location"
android:text="Deals"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="40dp"
android:paddingTop="10dp"
android:layout_toRightOf="@+id/location"
android:layout_below="@+id/deals"
android:text="Deals"
android:textSize="15dp"
android:textColor="#01458e"
android:textStyle="bold" />
<ImageView
android:id="@+id/cuisine"
android:src="@drawable/cuisine"
android:layout_width="60dp"
android:layout_height="80dp"
android:paddingTop="10dp"
android:paddingLeft="40dp"
android:layout_toRightOf="@+id/deals"
android:text="Cuisine"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/cuisine"
android:layout_below="@+id/cuisine"
android:text="Cuisine"
android:textSize="15dp"
android:textColor="#01458e"
android:textStyle="bold" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我在使用下面的类似图片后得到了
用这个 xml 代替你的 ...............
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<ImageView
android:id="@+id/test_image"
android:src="@drawable/test"
android:layout_width="match_parent"
android:layout_height="240dp"
android:scaleType="fitXY" />
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_gravity="center"
android:layout_margin="@dimen/card_margin"
android:elevation="3dp"
card_view:cardCornerRadius="@dimen/card_album_radius">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/location"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/whatsapp"
android:text="Location" />
<ImageView
android:id="@+id/deals"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/whatsapp"
android:text="Deals"/>
<ImageView
android:id="@+id/lastimage"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/whatsapp"
android:text="Deals"/>
<ImageView
android:id="@+id/cuisine"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/whatsapp"
android:text="Cuisine" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Location"
android:gravity="center"
android:textColor="#01458e"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Deals"
android:gravity="center"
android:textColor="#01458e"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Cuisine"
android:textColor="#01458e"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="LastText"
android:textColor="#01458e"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
注意:- 根据您的项目更改文本和图像....
你的图片看起来像这些......
享受编码......
给你。根据您的项目更改图像。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/test_image"
android:layout_width="match_parent"
android:layout_height="240dp"
android:scaleType="fitXY"
android:src="@drawable/bg_big" />
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:elevation="3dp"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/ic_eye" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Explore"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/location"
android:tint="@color/colorOrange" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Location"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/location"
android:tint="@color/colorOrange" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Deals"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/location"
android:tint="@color/colorOrange" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Cusine"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/car"
android:tint="@color/colorOrange" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Dive-in"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
看起来像这样:
在您的布局中,重新更正语法,其中 id=cusine,图像应为 b
width=80 and height=100.