2014-04-27 32 views
0

我想在android中實現以下文件。 enter image description hereButton的大小在android的xml文件中太不正常了

我實施至今如下:

enter image description here

這裏的按鈕在最後屏幕的尺寸過大。我不明白爲什麼按鈕的大小太大?

我的代碼如下:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF" 
    android:orientation="vertical" 
    android:padding="5dp" 
    android:weightSum="3" > 

    <RelativeLayout 
     android:id="@+id/relative_layout_1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#BDD6E0" 
     android:orientation="vertical" 
     android:padding="5dp" 
     android:paddingBottom="10dp" > 

     <TextView 
      android:id="@+id/textView_Welcome" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_toLeftOf="@+id/imageView_ProPic" 
      android:text="Welcome Back" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#000000" /> 

     <TextView 
      android:id="@+id/textView_Name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/textView_Welcome" 
      android:layout_toLeftOf="@+id/imageView_ProPic" 
      android:paddingLeft="10dp" 
      android:text="Sultan Ahmed Sagor" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#000000" /> 

     <ImageView 
      android:id="@+id/imageView_ProPic" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginBottom="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="5dp" 
      android:contentDescription="ProPic"/> 
    </RelativeLayout> 

    <TableLayout 
    android:id="@+id/table_layout_1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/relative_layout_1" 
    android:weightSum="8" > 

     <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" > 

       <TextView 
       android:id="@+id/settings_user_name_text" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="Instructional Use :" 
       android:gravity="center|left" 
       android:paddingLeft="10sp" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="#000000" /> 

      </TableRow> 

     <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" > 

       <TextView 
       android:id="@+id/settings_user_name_text3" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="Drug Name :  Gopten" 
       android:paddingLeft="10sp" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="#000000" /> 

      </TableRow> 

     <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="4" > 



       <TextView 
        android:id="@+id/text_instructions" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:background="@drawable/border_for_image" 
        android:maxLines="15" 
        android:paddingLeft="10sp" 
        android:text="@string/text_ins" 
        android:textColor="#000000" /> 

      </TableRow> 

     <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:background="@drawable/border_for_edit_text" 
     android:layout_margin="10sp" 
     android:layout_weight="1" > 

       <Button 
       android:id="@+id/settings_user_name_text" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="BACK" 
       android:gravity="center|center" 
       android:paddingLeft="10sp" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="#000000" /> 

      </TableRow> 



    </TableLayout> 

</RelativeLayout> 

你能幫我在那裏我有錯誤指出/爲什麼按鈕在最後屏幕的尺寸過大?

+0

你的按鈕,把所有的寬度:'機器人: layout_width =「match_parent」' –

回答

0

嘗試添加這對XML的按鈕移到

android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
2

你有你的按鈕設置爲「match_parent」,這將使其成長以適應大小的它的父(在這種情況下,這樣全寬) 。

嘗試(使它一樣大的文本):

<Button 
      android:id="@+id/settings_user_name_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

或(使之成爲具體尺寸):

<Button 
      android:id="@+id/settings_user_name_text" 
      android:layout_width="48dp" 
      android:layout_height="96dp" 
+0

替換此代碼給出相同的輸出 –

+0

將相同的東西應用於您的表格行(父代) – Booger

相關問題