我正在开发一个Android应用程序,我正在使用编辑文本。当我在其中放入长文本时,它会增加编辑文本的大小。我已经在宽度上给了"wrap_content"
并限制了行数和'ems'
但是它不起作用。
当我放长文本或短文本时,它会增加或减少编辑文本的大小。我发布了我的问题的XML代码和快照。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" First Name:"
android:textColor="@color/Black"
android:textSize="12sp" />
<EditText
android:id="@+id/fnametxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/Beige"
android:enabled="false"
android:lines="1"
android:ems="15"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ufyufgiuhjlkh"
android:textColor="@color/Black"
android:textSize="12sp" />
</LinearLayout>
只需修复textview的宽度大小:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/fname"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text=" First Name:"
android:textColor="@color/Black"
android:textSize="12sp" />
<EditText
android:id="@+id/fnametxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/Beige"
android:enabled="false"
android:lines="1"
android:ems="15"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ufyufgiuhjlkh"
android:textColor="@color/Black"
android:textSize="12sp" />
</LinearLayout>
使用下面的代码它工作正常:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" First Name:"
android:textColor="@color/Black"
android:textSize="12sp"
android:singleLine="true"/>
<EditText
android:id="@+id/fnametxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/Beige"
android:enabled="false"
android:lines="1"
android:ems="15"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ufyufgiuhjlkh"
android:textColor="@color/Black"
android:textSize="12sp" />
</LinearLayout>
尝试这个..通过给出宽度,它使设计兼容性复杂
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="bottom"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:id="@+id/fname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=" First Name:"
android:textColor="@android:color/black"
android:textSize="12sp"
android:layout_weight="1" />
<EditText
android:id="@+id/fnametxt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:layout_weight="3"
android:ems="15"
android:enabled="false"
android:lines="1"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ufyufgiuhjlkh"
android:textColor="@android:color/black"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>