2016-06-22 47 views
0

我正在嘗試獲取以下設計。考慮它是一個列表項。Android中的圖像,文本/圖片和圖像

enter image description here

但我下面的設計,它不給我design.The textviews來吧左圖像的頂部。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#FFFFFF"> 
    <ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_person_black_24dp" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:id="@+id/userimage" /> 
    <TextView 
    android:text="Text1" 
    android:layout_toRightOf="@id/userimage" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/username"/> 
    <TextView 
    android:text="Text2" 
    android:layout_below="@id/name" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 
    <ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_keyboard_arrow_right_black" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" /> 
</RelativeLayout > 

enter image description here

+0

'RelativeLayout'更適合這項任務 – Sunshinator

回答

0

取而代之的LinearLayout中使用的RelativeLayout,併爲TextViews使用:

機器人:layout_toRightOf = 「@ ID/userimage」 和

機器人:layout_alignTop =」 @ id/userimage「或

android:layout_alignBottom =」@ id/userimage「

+0

請檢查我的更新。 – hotspring

0

在這裏你去:當你有時間

<?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="match_parent" 
android:layout_height="wrap_content" 
android:background="#FFFFFF" 
android:orientation="horizontal"> 

<ImageView 
    android:id="@+id/userimage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentStart="true" 
    android:layout_centerVertical="true" 
    android:src="@drawable/ic_person_black_24dp" 
    tools:background="@mipmap/ic_launcher" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignBottom="@id/userimage" 
    android:layout_toEndOf="@id/userimage" 
    android:layout_toStartOf="@id/arrow" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/username" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center|start" 
     tools:text="Text1" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center|start" 
     tools:text="Text2" /> 
</LinearLayout> 

<ImageView 
    android:id="@+id/arrow" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" 
    android:layout_centerVertical="true" 
    android:src="@drawable/ic_keyboard_arrow_right_black" 
    tools:background="@mipmap/ic_launcher" /> 
</RelativeLayout> 

嘗試使用不同的佈局玩,這將極大地幫助你的未來。

編輯: 集中TextViews的更好的解決方案。

+0

它沒有工作。 – hotspring

+0

發生了什麼事?你現在可以描述這個問題嗎? – Marijan

+0

TextViews位於左側圖像的頂部。 – hotspring

0

試試這個:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="6dip" > 

<ImageView 
    android:id="@+id/userimage" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginRight="6dip" 
    android:contentDescription="TODO" 
    android:src="@drawable/ic_person_black_24dp" /> 

<ImageView 
    android:id="@+id/icon" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="6dip" 
    android:contentDescription="TODO" 
    android:src="@drawable/ic_keyboard_arrow_right_black" /> 


<TextView 
    android:id="@+id/username" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_above="@id/secondline" 
    android:layout_alignParentTop="true" 
    android:layout_toRightOf="@id/userimage" 
    android:layout_toLeftOf="@id/icon" 
    android:singleLine="true" 
    android:gravity="center_vertical" 
    android:text="Example username" 
    android:textSize="16sp" /> 

<TextView 
    android:id="@+id/secondline" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_weight="1" 
    android:layout_alignParentRight="true" 
    android:layout_toRightOf="@id/userimage" 
    android:layout_toLeftOf="@id/icon" 
    android:singleLine="true" 
    android:text="Description" 
    android:textSize="12sp" /> 

</RelativeLayout> 

我使用了一些dp大小,你沒有使用,並增加了一些其他的東西,但我想,這樣它適合你的願望,你可以改變它。我曾嘗試使用與您一樣的名字。總的來說,這應該工作,如果你稍微調整一下。

+0

它沒有工作 – hotspring

+0

@hotspring嘗試這個新的代碼,並確保如果他們是錯誤的調整一些參數(大小,名稱)。如果你調整了一些東西,這應該工作。 – REG1

+0

@hotspring你有沒有得到它的工作? – REG1

0

你在文本2問題使用它,它會工作

<TextView 
android:text="Text2" 
android:layout_below="@id/username" 
android:layout_toRightOf="@id/userimage" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" />