2014-04-27 53 views
0

我遇到了我的碎片xml的佈局問題......我想這可能是因爲佈局最初只是爲了一個活動而創建的,然後它被更改了到一個片段。它看起來像這樣在我的編輯器:Android - Layout xml中EditText的大小問題

img desc

但在我的手機和模擬器,它最終是這樣的:

enter image description here

誰能想到了我一個解決方案嗎?我已經嘗試了多件事情,但似乎無法修復它,因爲我認爲在處理碎片時規則可能有點不同。感謝您的一切和任何幫助!

<?xml version="1.0" encoding="utf-8"?> 

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

<LinearLayout android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/title" /> 
    <EditText android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 
</LinearLayout> 

<TextView android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/body" /> 
<EditText android:id="@+id/body" android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:scrollbars="vertical" /> 

<Button android:id="@+id/confirm" 
    android:text="@string/confirm" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

    </LinearLayout> 

的活動佈局文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 
<FrameLayout 
    android:id="@+id/frame1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView1" 
    android:layout_marginTop="130dp" 
    android:layout_toRightOf="@+id/textView1" > 
</FrameLayout> 
</LinearLayout> 
+1

你可以發表你的活動佈局 – Libin

回答

1

只要改變android:layout_widthmatch_parent。這將水平填充所有可用空間。

<TextView android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/body" /> 

<EditText android:id="@+id/body" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:scrollbars="vertical" /> 

<Button android:id="@+id/confirm" 
    android:text="@string/confirm" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

對於活動的佈局文件:

<FrameLayout 
    android:id="@+id/frame1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView1" 
    android:layout_marginTop="130dp" 
    android:layout_toRightOf="@+id/textView1" > 
</FrameLayout> 
0

您可以使用屬性 「EMS」 改變大小。

 <EditText 
      android:id="@+id/editText1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" > 

      <requestFocus /> 
     </EditText> 
0

爲您的文本的意見和編輯視圖嘗試match_parent而不是包裝內容

<TextView android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/title" /> 
<EditText android:id="@+id/title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/>