底部裁剪的Android正常屏幕大小
我已经创建了一个布局为正常屏幕大小与hdpi密度使用相对布局。但我知道一些屏幕尺寸相同的设备,底部被裁剪成7-8毫米,用于3个安卓常用按钮主页等等 现在我想知道如何创建布局以适应这种类型的设备,因为现在它将我的布局裁剪为7毫米 谢谢底部裁剪的Android正常屏幕大小,android,layout,size,screen,Android,Layout,Size,Screen,我已经创建了一个布局为正常屏幕大小与hdpi密度使用相对布局。但我知道一些屏幕尺寸相同的设备,底部被裁剪成7-8毫米,用于3个安卓常用按钮主页等等 现在我想知道如何创建布局以适应这种类型的设备,因为现在它将我的布局裁剪为7毫米 谢谢 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/prime"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8B008B"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="5dp"
tools:context="com.example.testznanja.MainActivity" >
<RelativeLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/question_layout" >
<TextView
android:id="@+id/questionText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<Button
android:id="@+id/beginTest"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_below="@+id/infoPanel"
android:layout_marginTop="25dp"
android:background="@drawable/button_normal"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/beginTest"
android:layout_marginTop="18dp"
android:background="@drawable/button_normal"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_marginTop="18dp"
android:background="@drawable/button_normal"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button3"
android:layout_marginTop="18dp"
android:background="@drawable/button_normal"
android:text="Button" />
<RelativeLayout
android:id="@+id/infoPanel"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_below="@+id/rl"
android:layout_marginTop="25dp"
android:background="@drawable/info_panel_layout"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<TextView
android:id="@+id/questionsAnswers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Skor: 0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="right"
android:text="Vreme: 20"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="50:50"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
你有没有试过用nexus系列的软菜单按钮在模拟器上测试它?这些手机的纵横比与galaxy s3、s4等其他手机相差不远。但为了回答您的问题,如果您真的希望布局灵活,我可以考虑以下三种选择: [1] 如果您不介意滚动,您可以将父RelativeLayout封装在。或者看看我修改过的xml文件。只需用您提供的抽屉更换即可:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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" >
<RelativeLayout
android:id="@+id/prime"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8B008B"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="5dp"
tools:context="com.example.testznanja.MainActivity" >
<RelativeLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/question_layout" >
<TextView
android:id="@+id/questionText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<Button
android:id="@+id/beginTest"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_below="@+id/infoPanel"
android:layout_marginTop="25dp"
android:background="@drawable/button_normal"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/beginTest"
android:layout_marginTop="18dp"
android:background="@drawable/button_normal"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_marginTop="18dp"
android:background="@drawable/button_normal"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button3"
android:layout_marginTop="18dp"
android:background="@drawable/button_normal"
android:text="Button" />
<RelativeLayout
android:id="@+id/infoPanel"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_below="@+id/rl"
android:layout_marginTop="25dp"
android:background="@drawable/info_panel_layout"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<TextView
android:id="@+id/questionsAnswers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Skor: 0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="right"
android:text="Vreme: 20"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="50:50"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<View
android:id="@+id/dummy"
android:layout_width="match_parent"
android:layout_height="800dp"
android:layout_below="@+id/button4"
android:background="#ff4444" />
</RelativeLayout>
</ScrollView>
注意,我添加了一个红色背景的视图,底部是android:id=@+id/dummy。这是为了让您看到滚动效果并模拟裁剪场景。如果你不需要,就把它取下来
[2] 如果您希望所有内容都能在屏幕中显示,而不必向下滚动,那么您应该将您的家长RelativeLayout转换为一个线性布局,并适用于每个孩子。这种方法更复杂,需要做很多工作,因为您必须计算每个子对象的权重,并且必须在xml中更改子对象的每个宽度和高度
[3] 重新设计布局,使其始终具有额外的空间以适应不同的设备纵横比,并重新设计图像和背景。我建议你在报纸上读一读
第一个是3个中最简单的一个。如果您希望您的布局尽可能灵活,我很抱歉,我的朋友,但我想不出一个更简单的方法来做到这一点。您能发布您的xml代码以便我们看到问题吗?我不需要模拟器,我的手机有软键,所以我在真实的设备上尝试,我的布局被它们裁剪了。我找到了一个使用keys.xml制作不同布局布局的解决方案,然后检查设备是否有软键,这取决于我使用一个或其他布局设置ContentView。不过谢谢你帮我,伙计。