Android 强制编辑文本占据滚动视图中的全屏
我在滚动视图中的Android 强制编辑文本占据滚动视图中的全屏,android,android-layout,Android,Android Layout,我在滚动视图中的LinearLayout中有一个EditText字段。只要不存在滚动视图,则布局_weight=“1.0”会让我的编辑文本占据剩余屏幕。但一旦我将LinearLayout包装在滚动视图中,它就会将编辑文本更改为一行,布局权重不起作用 我的完整布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" a
LinearLayout
中有一个EditText
字段。只要不存在滚动视图
,则布局_weight=“1.0”
会让我的编辑文本
占据剩余屏幕。但一旦我将LinearLayout包装在滚动视图中
,它就会将编辑文本
更改为一行,布局权重不起作用
我的完整布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" >
<TextView android:id="@+id/titleTextView"
style="@style/TitleHeaderBarText"
android:text="@string/announcement" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="right" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subject:"
android:textSize="16sp" />
<EditText
android:id="@+id/et_subject"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Announcement:"
android:textSize="16sp" />
<EditText
android:id="@+id/et_announcement"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0" />
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="24sp"
android:paddingRight="24dp"
android:text="Save" />
</LinearLayout>
</ScrollView>
</LinearLayout>
您需要添加ScrollView属性
android:fillViewport=“true”
:
。。。
....
编辑文本是否需要具有布局权重属性?如果您是LinearLayout,则将宽度设置为与父项匹配,则将EditText设置为与父项匹配将填充屏幕,因为它的方向为“垂直”。感谢您的回复。这正是我在这里发帖之前的想法和尝试。但那不起作用。再看一看你的布局文件,我发现开头标签不见了。您的实际布局xml中是否也缺少此内容?这里的语法格式化程序以某种方式删除了它,但当我去编辑它时,它就在那里。但不管怎样,当我在“这确实有效”之间加上一个空格时,它似乎就出现了。非常感谢。想知道fillViewport标记的作用是什么。
<?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" >
<TextView android:id="@+id/titleTextView"
style="@style/TitleHeaderBarText"
android:text="@string/login_title" />
<ScrollView
android:id="@+id/sv_weight_tell_us"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/bg_light_radial_pink" >
<LinearLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="12dp"
android:orientation="vertical" >
<TextView
android:id="@+id/login_header"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Login" />
<TableLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="@string/username" />
<EditText
android:id="@+id/et_username"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/password" />
<EditText
android:id="@+id/et_password"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:inputType="textPassword" />
</TableRow>
<TableRow>
<View/>
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/login"
android:padding="12dp" />
</TableRow>
</TableLayout>
<ProgressBar
android:id="@+id/pb_1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:indeterminate="true"
style="?android:attr/progressBarStyleSmall"
android:visibility="invisible" />
<TextView
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_weight="1.0" android:gravity="bottom"
android:text="@string/dont_have_Q" />
<TextView
android:id="@+id/tv_sign_up"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/sign_up_" />
</LinearLayout>
</ScrollView>
</LinearLayout>
...
<ScrollView
android:id="@+id/sv_weight_tell_us"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/bg_light_radial_pink"
android:fillViewport="true" >
....