【发布时间】:2017-06-14 20:02:43
【问题描述】:
我正在尝试将线性布局用作我的 recyclerView/adapter 的一行,基本上我的行有 3 个元素:一个图像、一个 textView 和一个带有一些文本的 checkButton。
我想要的是图像占据 50% 的宽度加上 40 的高度,所以我将图像的权重设置为 2。
接下来我需要另一个 50% 的布局,其中包含其他 2 个元素,我希望在图像的右上角是 textView,在底部是复选框。
我之前已经用相对布局实现了这个,但是内容不适应不同的设备,所以我尝试了线性布局和权重属性。
这就是我目前所拥有的:
<?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">
<ImageView
android:id="@+id/plantPhoto"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:contentDescription="photo " />
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:id="@+id/plantName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="@color/nephritis"
android:textSize="15sp" />
<CheckBox
android:id="@+id/plantCheck"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/plantName"
android:layout_below="@+id/plantName"
android:layout_marginTop="25dp"
android:button="@drawable/customdrawablecheckbox"
android:textSize="10dp" />
</LinearLayout>
这是我目前拥有的图像:image
正如我所解释的,我需要图像占据 50% 的宽度,并且绿色文本与右侧的照片并排。
复选框必须在下方,有帮助吗??
谢谢
【问题讨论】:
标签: java android xml android-layout android-linearlayout