设计自定义列表视图行 - 需要有关定位元素的建议

时间:2014-07-08 19:16:19

标签: android android-layout android-xml android-ui

所以这是我追求的基本布局:http://i.imgur.com/Y5rHEpc.jpg

在设计师中,我无法按照我想要的方式左对齐矩形。一切都重叠。 http://i.imgur.com/ufWmVgR.png

最好的解决方法是什么?我是新手,很难搞清楚这些布局。我正在使用我在drawables文件夹中创建的非常简单的矩形形状。

任何提示都很受欢迎..我真的在这里碰到了我的头。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/row_rectimage"
        android:layout_width="44dp"
        android:layout_height="match_parent"
        android:src="@drawable/rectangle" />

    <TextView
        android:id="@+id/row_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Some Title"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/row_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/row_title"
        android:layout_marginTop="5dp"
        android:text="Some Description"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="16sp" />

.....

1 个答案:

答案 0 :(得分:1)

这会添加另一个嵌套的LinearLayout,但性能损失应该可以忽略不计。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/row_rectimage"
        android:layout_width="44dp"
        android:layout_height="match_parent"
        android:src="@drawable/rectangle" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:paddingLeft="5dp" >

        <TextView
            android:id="@+id/row_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="Some Title"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/row_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/row_title"
            android:layout_marginTop="5dp"
            android:text="Some Description"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="16sp" />
    </LinearLayout>
</LinearLayout>
相关问题