2014-08-31 57 views
0

我已经使用相对布局为hdpi密度创建了正常屏幕尺寸的布局。但我知道一些屏幕尺寸相同的设备,其底部被裁剪为7-8毫米,用于3个android常用按钮(家庭等)。Android正常屏幕尺寸在底部修剪

现在我不知道如何创建布局以适应这种类型的设备,因为现在它裁剪我的布局7毫米?

谢谢。

<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> 

+0

你可以发布你的XML代码,以便我们可以看到问题吗? – chjarder 2014-09-01 02:05:31

+0

我发布.xml文件 – 2014-09-01 12:23:25

回答

0

你试过测试它与例如Nexus系列软菜单按钮的模拟器?这些手机的长宽比并不像s3,s4等其他手机那么远。但要回答你的问题,如果你真的希望你的布局灵活适应一切,我可以考虑3种选择:

[1]如果您不介意滚动,您可以将您的父亲RelativeLayout(@+id/prime)包装在ScrollView内。或者看看我修改的xml文件。只需更换您所提供的一个可绘制的:我加了View在底部红色背景和android:id="@+id/dummy"

<?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> 

通知。这是为了让您看到滚动效果并模拟裁剪方案。如果您不需要它,请将其移除。

[2]如果你想要的一切,以适应屏幕内,而不必向下滚动,您应该在父母的RelativeLayout转换成LinearLayoutuse weights为每一个孩子。这种方法比较复杂,需要做很多工作,因为你必须计算每个孩子的体重,并且你必须几乎改变你已经拥有的xml中每个孩子的宽度和高度。

[3]重新设计您的布局,使其始终有足够的空间以适应不同的设备长宽比,并重新设计您的图像和背景。我建议你阅读Android Design Guidelines

第一个是最简单的3.如果你希望你的布局尽可能灵活,我很抱歉我的朋友,但我想不出一个更简单的方法来做到这一点。

+0

我不需要模拟器,我的手机有软键,所以我尝试它在真实的设备上,我的布局被他们裁剪。我找到了一个制作不同布局(layoutWithKeys.xml)的解决方案,并且我检查设备是否具有软键,具体取决于我使用一个或其他布局的setContentView。不过谢谢你试图帮助我的队友。 – 2014-09-02 13:27:21