微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 以编程方式在布局中布局子视图

我正在尝试在平板电脑上以相对布局布局视图,就像书架一样.将会有这么多,然后创建一个新行.

我的初始状态如下:

  <ScrollView
    android:layout_marginTop="150sp"
    android:layout_marginLeft="50sp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
      android:id="@+id/user_list"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">

      <!-- Add User Avatar -->
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <ImageView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:src="@drawable/user_frame" />
            <ImageView
                android:id="@+id/demo_image"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:src="@drawable/add_user"
                android:layout_marginLeft="10px" />
            <ImageView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:src="@drawable/user_name_background"
                android:layout_marginLeft="10px" />
            <TextView
                android:id="@+id/user_name"
                android:layout_width="180px"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textStyle="bold"
                android:gravity="center_horizontal"
                android:text="Add New User" />
        </RelativeLayout>

      </RelativeLayout>
  </ScrollView>

我正在从数据库获取记录,对于每个记录,我需要放置一个版本的“添加用户头像”部分,如上所示.我想做5,然后换成新行.

我最初的想法是使用布局inflater并以编程方式添加视图,使用RelativeLayout.LayoutParams来设置layout_toRightOf值.

必须有一个更简单的方法.我见过许多使用“书架”比喻的应用程序.

解决方法:

我能想到几个选项.

>为什么不使用LinearLayouts和水平属性,而不是使用相对布局?
>使用TableLayout,非常类似于LinearLayout
>使用带有自定义适配器的ListView为每个ListRow填充五个“添加用户头像”

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐