【发布时间】:2019-11-12 14:24:09
【问题描述】:
我有以下 XML 文件 -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="13dp"
android:padding="13dp"
android:background="@color/white"
android:orientation="vertical">
<ImageView
android:id="@+id/products_row_item_product_image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/products_row_item_product_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:text="@string/fragment_marketplace_products_row_item_product_title"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/products_row_item_description_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:text="@string/products_row_item_product_description" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/very_light_grey" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="5dp"
android:orientation="horizontal">
<TextView
android:id="@+id/products_row_item_price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/products_row_item_price_text"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="@+id/products_row_item_likes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fragment_marketplace_products_row_item_likes"
android:textSize="17sp" />
<ImageView
android:id="@+id/products_row_item_heart_image_view"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:scaleType="fitXY"
android:src="@drawable/like_heart" />
</LinearLayout>
</LinearLayout>
看起来像这样 - (相当混乱,这就是我在这里的原因:))
我的目标是让 XML 看起来像这样 -
所以我需要更改以下问题 -
1) 价格标签需要在开头,喜欢的数量和图片应该在结尾。试图在结束/开始时将重力和 layout_gravity 都放在它们身上 - 没有任何变化。为什么?
2)无论我得到什么图像,图像都需要保持一致。如何确保图像始终保持不变?
3) 底部线性布局太大。我需要把它缩小 - 试图玩弄它的高度并弄得一团糟。
4) 任何其他明显的差异将不胜感激
【问题讨论】:
-
这样的事情在
RelativeLayout中比LinearLayout更容易安排。 -
@dguy 我觉得我做得很好,但只需要一些调整
标签: android xml android-linearlayout