【发布时间】:2016-03-31 15:10:46
【问题描述】:
我有一个带有EditText 的布局,如下所示:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
.....
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/some_button">
<EditText
android:id="@+id/some_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="@string/some_text_hint"/>
.....
</RelativeLayout>
</RelativeLayout>
在横向模式下,此布局的行为不一致。在手机上呈现时,some_text 在对焦时会被提取到全屏,这很好。但是,使用这种精确布局,some_text 如果出现在平板电脑上,将不会被提取。我也希望将文本框提取到平板电脑上的全屏。
我正在使用运行 Android 4.2.2 (API 17) 的 Nexus 5 手机和 Nexus 7 平板电脑模拟器预设进行测试。
统一更新: 在运行 Android 5.1 的三星 Galaxy Tab E 设备和运行 Android 5.1 的模拟器上的任何编辑文本都会重现此问题。
UPD2: 我创建了一个测试empty project,只是为了验证它确实是一个普通文本框问题。它是。现在我的布局看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.myapplication.MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This should be fullscreen"/>
</RelativeLayout>
这是一个活动代码,以防万一:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
还有一些图片,只是因为。这就是布局在手机上正确呈现的方式(模拟的和物理的):
这就是我在平板电脑上得到的:
【问题讨论】:
-
您是在实际设备上试用它们,还是根据模拟器结果做出该声明?
-
您的 EditText 没有以横向模式显示?我说的对吗?
-
@Shark 我收到了来自使用物理设备的最终用户的错误报告,并设法用模拟器重现了相同的行为。
-
@VladimirKulyk,文本框在那里,它可以很好地获得焦点并接收输入,但它没有被提取。
-
您是否从您的 sn-p 中省略了其他视图?可能屏幕太小,无法将它们全部挤进去。要么使某些视图的高度动态化,要么使整体或部分可滚动。
标签: android android-layout android-edittext