2017-07-24 70 views
0

我試圖創建這個接口:thisAndroid界面問題

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/displayGenericDialog" 
    android:weightSum="1" 
    android:background="#99000000" 
    android:layout_marginBottom="20dp" 
    android:layout_marginLeft="250dp" 
    android:layout_marginRight="250dp" 
    android:layout_marginTop="20dp"> 

    <LinearLayout 
     android:id="@+id/displayMessageTop" 
     android:layout_width="match_parent" 
     android:layout_height="0px" 
     android:layout_weight="0.15" 
     android:orientation="horizontal" 
     android:weightSum="100"> 

     <TextView 
      android:id="@+id/textMessageTitle" 
      android:layout_width="910dp" 
      android:layout_height="match_parent" 
      android:layout_weight="90" 
      android:gravity="center|left" 
      android:paddingLeft="100sp" 
      android:textColor="#ffffffff" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/displayMessageCenter" 
     android:layout_width="match_parent" 
     android:layout_height="0px" 
     android:layout_weight="0.58" 
     android:orientation="horizontal" 
     android:weightSum="1"> 
     <TextView 
      android:id="@+id/textMessageText" 
      android:layout_width="0px" 
      android:layout_height="492dp" 
      android:layout_weight="1" 
      android:gravity="left|center" 
      android:paddingLeft="40sp" 
      android:paddingRight="40sp" 
      android:textColor="#ffffffff" /> 
     <ImageView 
      android:id="@+id/messagePicture" 
      android:layout_width="0px" 
      android:layout_height="match_parent" 
      android:layout_weight="0.5" 
      android:scaleType="fitXY" 
      android:adjustViewBounds="true" 
      android:layout_gravity="center" 
      android:visibility="gone" 
      android:background="@drawable/image_view_border" 
      android:layout_margin="70sp" /> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/displayMessageBottom" 
     android:layout_width="match_parent" 
     android:layout_height="0px" 
     android:layout_weight="0.11" 
     android:weightSum="1" 
     android:orientation="horizontal"> 
     <ImageButton 
      android:id="@+id/sendResponseIB" 
      android:layout_width="0px" 
      android:layout_height="wrap_content" 
      android:background="@drawable/panel_x" 
      android:gravity="center" 
      android:layout_weight="0.1" 
      android:onClick="closeProtip" /> 
     <TextView 
      android:id="@+id/leftTextGenericDialog" 
      android:layout_width="0px" 
      android:layout_height="match_parent" 
      android:paddingLeft="10sp" 
      android:layout_weight="0.4" 
      android:clickable="true" 
      android:textColor="#ff72CCCC" 
      android:layout_marginTop="20dp" 
      android:gravity="center"/> 
     <ImageButton 
      android:id="@+id/rightPictureGenericDialog" 
      android:layout_width="0px" 
      android:layout_height="wrap_content" 
      android:paddingTop="5sp" 
      android:layout_weight="0.1" 
      android:background="@drawable/panel_x" 
      android:onClick="closeP" /> 
    </LinearLayout> 

</LinearLayout> 

背景設定編程,因爲頭顏色可以變動內容。 enter image description here First TextView textMessageTitle用於白色標題,並以編程方式設置爲大小50和粗體。

第二個textMessageText是字體大小40.如果顯示的消息只包含文本而沒有圖像,則文本應居中,否則應該留下文本的一半和圖像的右半部分。 我已經試過:

if(image) 
    TextView.setPadding(200, 0, 200, 0); 
else 
    TextView.setPadding(20, 0, 20, 0); 

下的TextView rightTextGenericDialog是一個與Send response文字和sendResponseIB是對文本的左側圖像按鈕。 TextView和Image按鈕應該在中心位置進行排列,在中心線下方和下方應該是緊密的ImageButton。

問題是我的界面看起來不像應該。 我是Android編程新手,請您保持溫柔。

+0

你解決了這個問題嗎?下面的答案是否有效? –

+1

感謝您的回答! – Dana

回答

0

我不認爲這會馬上爲你工作。我對權重和佈局做了一些改變。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/displayGenericDialog"> 

    <LinearLayout 
     android:id="@+id/displayMessageTop" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/textMessageTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAlignment="center" 
      android:padding="16dp" 
      android:textColor="#ffffffff" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/displayMessageCenter" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:orientation="horizontal" 
     android:layout_weight="1" 
     android:layout_gravity="center"> 
     <TextView 
      android:id="@+id/textMessageText" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:paddingLeft="40sp" 
      android:layout_gravity="center" 
      android:paddingRight="40sp" 
      android:textColor="#ffffffff" /> 
     <ImageView 
      android:id="@+id/messagePicture" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:scaleType="fitXY" 
      android:adjustViewBounds="true" 
      android:layout_margin="70sp" /> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/displayMessageBottom" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal"> 
     <ImageButton 
      android:id="@+id/sendResponseIB" 
      android:layout_width="0dp" 
      android:layout_height="16dp" 
      android:background="@drawable/panel_x" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      android:onClick="closeProtip" /> 
     <TextView 
      android:id="@+id/leftTextGenericDialog" 
      android:layout_width="0dp" 
      android:layout_height="16dp" 
      android:paddingLeft="10sp" 
      android:layout_weight="1" 
      android:clickable="true" 
      android:textColor="#ff72CCCC" 
      android:layout_marginTop="20dp" 
      android:layout_gravity="center"/> 

    </LinearLayout> 

    <ImageButton 
     android:id="@+id/rightPictureGenericDialog" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="5sp" 
     android:layout_gravity="center" 
     android:layout_weight="0.1" 
     android:background="@drawable/panel_x" 
     android:onClick="closeP" /> 

</LinearLayout> 

試試這個,讓我知道如果這不符合您的要求。