2014-04-27 49 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"/>