0

enter image description here

The image above has many problems starting with the icon is not top aligning with the image. Also, I'd love to have UserName centered with respect to the icon.

Finally, I want to have the last line aligned with the bottom of the Image to the left.

I started using layout_weight and i couldn't get it to work. So, I applied hard widths and heights.

Ideally, I would like to have the first ImageView occupy 30% of the row. The Icon would occupy 7% and the rest will be allocated to the textview on first row.

Thanks for your suggestions.

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/custom_shape"
                >

    <ImageView
        android:id="@+id/imgVideo"
        android:src="@drawable/video_default_preview"
        android:layout_width = "150dp"
        android:layout_height= "150dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"/>

    <ImageView
        android:id="@+id/imgOwner"
        android:layout_width = "35dp"
        android:layout_height= "35dp"
        android:src="@drawable/icon_default_avator"
        android:layout_marginBottom="10dp"
        android:layout_alignTop="@+id/imgVideo"
        android:layout_marginRight="10dp"
        android:layout_toRightOf="@id/imgVideo"/>

    <TextView
        android:id="@+id/txtUserName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Plus"
        android:layout_marginBottom="10dp"
        android:layout_toRightOf="@id/imgOwner"/>

    <TextView
        android:id="@+id/txtVideoTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Mercedes SL 55"
        android:textSize="10sp"
        android:layout_marginBottom="10dp"
        android:layout_alignLeft="@+id/imgOwner"
        android:layout_below="@id/imgOwner"/>

    <TextView
        android:id="@+id/txtVideoName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="European Car ..."
        android:textSize="10sp"
        android:layout_alignLeft="@+id/txtVideoTitle"
        android:layout_below="@+id/txtVideoTitle"
        />
</RelativeLayout>
4

2 回答 2

2

我已经按照您的描述修改了您的 xml。

理想情况下,我希望第一个 ImageView 占据该行的 30%。Icon 将占据 7%,其余的将分配给第一行的 textview。

为此,您应该使用具有权重属性的线性布局。(第一张图片为 30%,其他图片为 70%。70% 的 7% 等于图标内部的 %10)

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

    <ImageView
        android:id="@+id/imgVideo"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_weight="3"
        android:scaleType="centerInside"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="7"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/imgOwner"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:scaleType="centerInside"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:id="@+id/txtVideoTitle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="10"
                android:text="Mercedes SL 55"
                android:textSize="10sp" />
        </LinearLayout>

        <TextView
            android:id="@+id/txtVideoName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="European Car ..."
            android:textSize="10sp" />

        <TextView
            android:id="@+id/txtUserName"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="Plus" />
    </LinearLayout>

</LinearLayout>
于 2013-11-06T20:14:17.960 回答
0
// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:layout_width="match_parent">

    <ImageView
        android:layout_height="150dp"
        android:layout_width="150dp"
        android:src="@drawable/ic_launcher"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"/>

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

        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:gravity="center_vertical">

            <ImageView
                android:layout_height="35dp"
                android:layout_width="35dp"
                android:src="@drawable/ic_launcher"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"/>

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:textSize="10sp"
                android:layout_marginLeft="5dp"
                android:text="Plus"/>
        </LinearLayout>

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="10sp"
            android:layout_marginTop="5dp"
            android:text="Mercedes SL 55"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="10sp"
            android:layout_marginTop="5dp"
            android:text="European Car ..."/>

    </LinearLayout>
</LinearLayout>
于 2013-11-07T03:58:00.933 回答