2017-04-05 38 views
0

的邊緣我的下一個糟糕的設計爲Android:佈局困難。保持文本的視圖右側,直到父母

enter image description here

我需要保持More infos有圖標的黑色文本的右側。如果Item 1 of 1將是一個更長的字符串,它會將圖標+文本推向右側。我無法弄清楚的問題是,如果左邊的文本太長而無法放在一行中,我希望More infos被推送到其父文件的右邊緣並停留在那裏,左邊的黑色文本應該跳轉到一條新線。

但是,這不是HTML的行爲就是這樣! :)關於如何實現這一點的任何想法?

我真的想要求設計師改變設計的。

編輯

我所做的它看起來像上面:

<RelativeLayout ...> 

<!--TEXT--> 
<TextView 
    android:id="@+id/list_item_form_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="@dimen/app_spacing_x0_5" 
    android:layout_marginTop="@dimen/app_spacing_x3" 
    android:textColor="@color/app_black" 
    android:textSize="@dimen/app_text_tiny" /> 

<!--VIEW DETAILS--> 
<TextView 
    android:id="@+id/list_item_view_details_btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:minWidth="50dp" 
    android:layout_toRightOf="@id/list_item_form_text" 
    android:layout_alignTop="@id/list_item_form_text" 
    android:drawableLeft="@drawable/ic_camera" 
    android:drawablePadding="@dimen/app_spacing_x0_3" 
    android:text="@string/f_form_front_view_details" /> 

</RelativeLayout> 
+0

你可以分享你已經嘗試過? –

+0

當然。看到編輯...這真的不是一個好方法。 – AndreiBogdan

回答

2

你可以做到這一點與LinearLayout

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:orientation="horizontal"> 

<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="test"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="123444"/> 

</LinearLayout> 

的關鍵是具有線性佈局與wrap_content和第一視圖與weight=1width=0dp

+0

它看起來像這樣如果我這樣做.... http://puu.sh/vadsq/4740132f82.png :( – AndreiBogdan

+0

是'linearlayout'與WRAP_CONTENT? –

+0

哈!不,那不是!...什麼是虛擬的!(我正在談論自己)。是的...這是正確的解決方案!!謝謝!我想知道這種「hack-ish」方法在所有操作系統上是否可以接受 – AndreiBogdan

0

也許是這樣的:

<!--TEXT--> 
<TextView 
    android:id="@+id/list_item_form_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" 
    android:layout_marginTop="5dp" 
    android:text="Long long long long text Long long long long text" 
    android:layout_toStartOf="@+id/list_item_view_details_btn" 
    android:layout_alignParentStart="true"/> 

<!--VIEW DETAILS--> 
<TextView 
    android:id="@+id/list_item_view_details_btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:minWidth="50dp" 
    android:layout_alignParentEnd="true" 
    android:layout_alignTop="@id/list_item_form_text" 
    android:text="More infos"/> 

結果是:

enter image description here

+0

什麼是'long long ...'文本很短? 'list_item_view_details_btn'將與右邊緣對齊,這不是OP所需要的。 – azizbekian

+0

如果你已經寫好了,用較小的長度文本嘗試一下......我猜測更多的信息將對齊到父母的右側,而不是左側文本的右側,不是? – AndreiBogdan