目前我每行有 2 张图片(通过 Picasso 加载),每张图片的右上角都有一个复选框。当我尝试添加 ScrollView 时,复选框的位置发生了变化,并且出现了一个额外的行。我怎样才能添加它并以正确的顺序保持可视化的其余部分?到目前为止,这是我的代码(连续):
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="false"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linLay"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text=""
android:background="@android:color/white"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="@+id/img2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text=""
android:background="@android:color/white"/>
</RelativeLayout>
</LinearLayout>
最佳答案
将 UI 元素的属性设置为父 UI 元素的 Right 和 Left。
android:layout_below="@id/name"
android:layout_toRightOf="@id/description"
android:layout_toLeftOf="@id/description"
编辑: 我为您制作了这个示例代码:这不是确切的,您可以从中了解。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:id="@+id/parentLayout"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<RelativeLayout
android:layout_width="0dp"
android:layout_toRightOf="@+id/parentLayout"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text=""
android:background="@android:color/white"/>
</RelativeLayout>
检查此链接:Layout File - Positioning Item to Right of Another Item (Android)
关于android - 如何在不改变其他元素可视化的情况下添加 ScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40191124/