简体   繁体   English

Android EditText布局宽度全尺寸

[英]Android EditText Layout Width Full size

I am new to Android and i am creating a test app for learning and in this i want my Edit-text field width to be as wide as the Device is ie EditText field should filled 100% of width as long as the Device width . 我是Android的新手,我正在创建一个用于学习的测试应用程序,为此,我希望我的Edit-text字段的宽度与Device一样宽,即EditText字段应填充与Device width一样长的宽度的100%。

I tried everything but didn't succeed.Any Clue What can i do here? 我尝试了一切,但没有成功。任何提示我在这里可以做什么?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:enabled="false"
    android:gravity="center_vertical|center"
    android:inputType="none"
    android:onClick="doDis"
    android:text="@string/aarti_collection" />

Try this... 尝试这个...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:enabled="false"
    android:gravity="center_vertical|center"
    android:inputType="none"
    android:onClick="doDis"
    android:text="@string/aarti_collection" />

Replace this 取代这个

android:layout_width="wrap_content" 
// since you have wrap_content  it will not take the full width

By 通过

android:layout_width="match_parent

for LinearLayout 用于LinearLayout

All the best for your developemnt. 一切为了您的发展。

Read this http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html 阅读此http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html

fill_parent (deprecated and renamed MATCH_PARENT in API Level 8 and higher) fill_parent(API级别8及更高版本中已弃用并重命名为MATCH_PARENT)

Setting the layout of a widget to fill_parent will force it to expand to take up as much space as is available within the layout element it's been placed in. It's roughly equivalent of setting the dockstyle of a Windows Form Control to Fill. 将小部件的布局设置为fill_parent将迫使其扩展以占用其所放置的布局元素内的可用空间。这大致相当于将Windows窗体控件的停靠样式设置为Fill。

Setting a top level layout or control to fill_parent will force it to take up the whole screen. 将顶层布局或控件设置为fill_parent将强制其占据整个屏幕。

wrap_content 包装内容

Setting a View's size to wrap_content will force it to expand only far enough to contain the values (or child controls) it contains. 将View的大小设置为wrap_content将迫使其仅扩展到足以容纳其包含的值(或子控件)的程度。 For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. 对于控件-例如文本框(TextView)或图像(ImageView)-这将包裹所显示的文本或图像。 For layout elements it will resize the layout to fit the controls / layouts added as its children. 对于布局元素,它将调整布局的大小以适合作为其子级添加的控件/布局。

It's roughly the equivalent of setting a Windows Form Control's Autosize property to True. 大致相当于将Windows窗体控件的Autosize属性设置为True。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM