android - 如何在不改变其他元素可视化的情况下添加 ScrollView?

标签 android scrollview

目前我每行有 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/

相关文章:

java - 当我将 recyclerview 版本从 23.0.1 更改为 23.2.1 时,gradle 文件错误

android - 排毒构建成功但排毒测试失败

c# - Xamarin android C# ScrollView OnScrollChanged 事件

android - SEND_SMS 权限 |对话框消息显示此应用程序可以查看短信

android - C :\Program Files\Java\jdk1. 6.0\bin>keytool.exe 不是有效的 win32 应用程序

android - google places api 被弃用后如何使用地点选择器

android - 如何在 Activity 中使用 ScrollView 创建多行编辑文本?

iOS:UIScrollView 以编程方式缩放不起作用

java - 如何在 ScrollView 中更改按钮触摸时的颜色?

java - 无法使用 Java 客户端使用 Appium 滚动 Android 应用程序