2011-07-05 101 views
0

我設計的安卓定製的對話,爲此我設計的XML文件作爲查看無法正常顯示Android的佈局

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

    <TextView android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/custom_dialog_text" 
    android:textColor="#000000" 
    android:textSize="14dip" 
    android:typeface="serif" 
    android:singleLine="false" 
    android:text="You are not authorized to use this application." 
    android:layout_marginTop="10dip"/> 

    <Button android:id="@+id/custom_button_ok" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Ok" 
    android:layout_below="@+id/custom_dialog_text" 
    android:layout_toRightOf="@+id/custom_dialog_text"/> 


</RelativeLayout> 

問題:

我想表明,在結束按鈕(右)的TextView,和textview的文本應該在多行(如果更多的字符必須顯示)。但是當我使用這種佈局時,按鈕不會出現在任何地方。

我還使用了LinearLayout和TableLayout,並且在這兩種情況下,按鈕都顯示一小部分。我錯在哪裏?

回答

1

基本上你要告訴按鈕將右對齊,把它需要的所有空間,然後剩下的空間給TextView。通過爲按鈕指定android:layout_layout_alignParentRight="true"併爲TextView指定android:layout_toLeftOf="@id/custom_button_ok"。注意訂單!

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@color/item_bg_color" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> 
    <Button android:id="@+id/custom_button_ok" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Ok" 
    android:layout_layout_alignParentRight="true" /> 

    <TextView android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/custom_dialog_text" 
    android:textColor="#000000" 
    android:textSize="14dip" 
    android:typeface="serif" 
    android:singleLine="false" 
    android:text="You are not authorized to use this application." 
    android:layout_marginTop="10dip" 
    android:layout_toLeftOf="@id/custom_button_ok" 
    /> 
</RelativeLayout> 
0

對於按鈕添加屬性的android:layout_alignParentRight,安卓layout_below,他們幫助你

0

上來試試這個..

<TextView android:layout_width="100dip" 
    android:layout_height="wrap_content" 
    android:id="@+id/custom_dialog_text" 
    android:textColor="#000000" 
    android:textSize="14dip" 
    android:typeface="serif" 
    android:singleLine="false" 
    android:text="You are not authorized to use this application." 
    android:layout_marginTop="10dip"/> 
0

layout_belw和layout_rightof屬性設置爲相同的ID在文本view.Just使用layout_below.Also U可以設定按鈕的重力底部

0

請嘗試以下代碼

<?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" android:weightSum="1.0"> 
    <RelativeLayout android:layout_height="wrap_content" 
     android:layout_width="0dp" android:layout_weight="0.85"> 
     <TextView android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:id="@+id/custom_dialog_text" 
      android:textColor="#FFFFFF" android:textSize="14dip" 
      android:typeface="serif" android:singleLine="false" 
      android:text="You are not authorized to use zdsaddsad this application." 
      android:layout_marginTop="10dip" /> 
    </RelativeLayout> 
    <RelativeLayout android:layout_height="wrap_content" 
     android:layout_width="0dp" android:layout_weight="0.15"> 
     <Button android:id="@+id/custom_button_ok" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:text="Ok" /> 
    </RelativeLayout> 

</LinearLayout> 
+0

你的答案是爲我工作,但你看到佈局的深度?這是僅有兩種觀點的好設計嗎? –

+0

如果你使用重量總和的概念,最好的是從來沒有你的設計打破任何屏幕,以便我已經使用過。如果找到這個答案正在工作,然後upvote它可以直接給textview和按鈕以總和概念 – Nikhil

+0

。 – Nikhil