подравнете иконите на реда на таблицата за android

Здравейте, имам проблеми с подравняването на 2 икони и текстов изглед в центъра на иконите. всъщност първата икона и текстът са подравнени правилно, но последната икона "playIcon" не е подравнена. Искам го в десния ъгъл... всички са подравнени. това е, което имам въведете описание на изображението тук

--

това е моят XML

    <?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="false"
    android:descendantFocusability="blocksDescendants"
    tools:context=".MainActivity" >

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:stretchColumns="3"
        android:layout_margin="5dp" >

        <ImageView
            android:id="@+id/img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:contentDescription="TODO" />

        <TextView
            android:id="@+id/txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"         
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:textColor="#FFF"
            android:textSize="@dimen/text_size"
            android:textStyle="bold|italic"
            android:typeface="serif" />

        <ImageView
            android:id="@+id/playbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

             />

person Kawakuti    schedule 22.08.2014    source източник


Отговори (1)


Можете да използвате RelativeLayout за подравняване на изображения отляво и отдясно. Нещо като този код:

    <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:contentDescription="TODO"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@id/img"
        android:layout_toLeftOf="@id/img2"
        android:gravity="center"
        android:text="Test"/>

    <ImageView
        android:id="@+id/img2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:contentDescription="TODO"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

Използвайте android:layout_alignParentLeft="true" за ляво изображение и android:layout_alignParentRight="true" за дясно изображение. също използвайте android:layout_centerVertical="true" и за двете.

Надявам се, че този код ще бъде полезен

person Ali Mehrpour    schedule 22.08.2014