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填充五个“添加用户头像”

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...