2017-07-24 72 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> 

试试这个,让我知道如果这不符合您的要求。