【问题标题】:creating LinearLayout item view创建 LinearLayout 项目视图
【发布时间】:2014-04-17 20:43:34
【问题描述】:

我一直在 xml 中创建一个 linearLayout 项目,最后它应该看起来像:

这是我写的代码:

<LinearLayout
                android:id="@+id/photoslayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/lightSeperator"
                android:orientation="vertical" >

                <!-- Review -->
//item starts here
                <LinearLayout
                    android:id="@+id/one_photo_layout"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/menu_button_bg"
                    android:orientation="vertical" >

                    <LinearLayout
                        android:id="@+id/top_layout"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:orientation="horizontal" >

                        <ImageView
                            android:id="@+id/photo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:visibility="visible" />

                        <TableLayout
                            android:id="@+id/table"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" >

                            <TableRow
                                android:id="@+id/row"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content" >

                                <ImageButton
                                    android:id="@+id/delete_pic"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:background="@drawable/delete_button_bg" />

                                <TextView
                                    android:id="@+id/text"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content" />
                            </TableRow>
                        </TableLayout>
                    </LinearLayout>
                </LinearLayout>

                <!-- Photos -->

            </LinearLayout>

我不能得到我需要的结果。也许有人可以给我看好的教程网站或帮助这个 xml 吗?

【问题讨论】:

  • 请放一张现在的样子
  • 现在不能这样做,它的所有东西都是从左到右放置的
  • 正如其他人所说,您应该使用RelativeLayout

标签: android android-linearlayout


【解决方案1】:

LinearLayout 不是正确的方法。你想要的是一个RelativeLaout,左边是图片,右边是删除按钮,中间是文本 - 像这样:

<RelativeLayout
    android:id="@+id/photoslayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/lightSeperator"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/photo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:visibility="visible" />

    <ImageButton
        android:id="@+id/delete_pic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@drawable/delete_button_bg" />

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/photo"
        android:layout_toLeftOf="@id/delete_pic" />

</RelativeLayout>

【讨论】:

    【解决方案2】:

    在你的情况下最好使用相对布局

    http://developer.android.com/guide/topics/ui/layout/relative.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-23
      • 2014-09-02
      • 2021-01-12
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 2011-03-23
      • 1970-01-01
      相关资源
      最近更新 更多