2016-03-05 40 views
1

我使用five different layouts针对不同屏幕尺寸的手机,如布局,layout-320dplayout-480dplayout-600dplayout-720dp不同。在使用手机samsung note3samsung GT-S7582测试我的应用程序时,这两款手机采用layout-320dp,但对齐方式各不相同。它的工作为note-3但对齐错位在GT-S7582。如果我改变任何东西note-3也影响GT-S7582。在这里,我添加了布局代码和屏幕截图供您参考。如何使这两款手机对齐为完美。两种不同屏幕尺寸的移动tooks 320布局,但比对得到各机器人

布局代码

<?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:layout_gravity="center" 
    android:background="@color/appblue" 
    android:orientation="vertical"> 



    <ImageButton 
     android:id="@+id/search_btn" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="100dp" 
     android:layout_marginTop="30dp" 
     android:background="@drawable/search_blue" 
     android:gravity="center" /> 

    <TextView 
     android:id="@+id/searchCollege" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="100dp" 
     android:layout_marginTop="15dp" 
     android:text="@string/search_college" 
     android:textColor="@color/green" 
     android:textSize="12sp" /> 

    <ImageButton 
     android:id="@+id/fav_btn" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="100dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="-110dp" 
     android:background="@drawable/fav_blue" 
     android:gravity="center" /> 

    <TextView 
     android:id="@+id/myFavourites" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="220dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="15dp" 
     android:text="@string/my_favourites" 
     android:textColor="@color/green" 
     android:textSize="12sp" /> 

    <ImageButton 
     android:id="@+id/profile_btn" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="100dp" 
     android:layout_marginTop="40dp" 
     android:background="@drawable/profile_blue" 
     android:gravity="center" /> 

    <TextView 
     android:id="@+id/myProfile" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="50dp" 
     android:layout_marginRight="100dp" 
     android:layout_marginTop="15dp" 
     android:text="@string/my_profile" 
     android:textColor="@color/green" 
     android:textSize="12sp" /> 

    <ImageButton 
     android:id="@+id/notification_btn" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="100dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="-110dp" 
     android:background="@drawable/notification_blue" 
     android:gravity="center" /> 

    <TextView 
     android:id="@+id/notification" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="230dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="15dp" 
     android:text="@string/notification" 
     android:textColor="@color/green" 
     android:textSize="12sp" /> 

    <ImageButton 
     android:id="@+id/reminder_btn" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="100dp" 
     android:layout_marginTop="40dp" 
     android:background="@drawable/reminder_blue" 
     android:gravity="center" /> 

    <TextView 
     android:id="@+id/reminder" 
     android:layout_width="wrap_content" 
     android:layout_height="80dp" 
     android:layout_marginLeft="55dp" 
     android:layout_marginRight="100dp" 
     android:layout_marginTop="15dp" 
     android:text="@string/reminder" 
     android:textColor="@color/green" 
     android:textSize="12sp" /> 

    <ImageButton 
     android:id="@+id/logout_btn" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="100dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="-175dp" 
     android:background="@drawable/logout_blue" 
     android:gravity="center" /> 

    <TextView 
     android:id="@+id/logout" 
     android:layout_width="wrap_content" 
     android:layout_height="80dp" 
     android:layout_marginBottom="50dp" 
     android:layout_marginLeft="240dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="15dp" 
     android:text="@string/logout" 
     android:textColor="@color/green" 
     android:textSize="12sp" /> 
    <FrameLayout 
     android:id="@+id/frame_container" 
     android:layout_width="1000dp" 
     android:layout_height="100dp" 
     android:layout_gravity="center" 
     > 
    </FrameLayout> 


</LinearLayout> 

笔记3

screen shot of note-3

的GT-S7582

screen shot of GT-S7582

截屏的截屏

回答

0

为了使您的设计响应使这些值文件夹像layout-480dp新建文件夹values-480do,并为他人分别布局values-600dpvalues-720dp

然后每个文件夹中做一个资源文件名dimen并在此文件中添加您的按钮的高度,宽度,边缘顶等

像这样:

<dimen name="button_width">80dp</dimen> 
<dimen name="button_height">80dp</dimen> 
<dimen name="margin-left">10dp</dimen> 
<dimen name="margin-right">100dp</dimen> 
<dimen name="margin-top">30dp</dimen> 

,并添加在你的xml里是这样的:

<ImageButton 
     android:id="@+id/search_btn" 
     android:layout_width="@dimen/button_width" 
     android:layout_height="@dimen/button_height" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="@dimen/margin_left" 
     android:layout_marginRight="@dimen/margin_right" 
     android:layout_marginTop="@dimen/margin_top" 
     android:background="@drawable/search_blue" 
     android:gravity="center" /> 

然后为了设置对齐layout-320dp更改dimen valuesvalues-320dp文件夹

尝试它有效4 u。多数民众赞成在Android的真正方式,使您的设计响应。

0

Galaxy S Dous作为ppi的233,而注释3的ppi为386,这就是为什么会发生这种情况。而不是硬编码frame_container的大小,而是使用dimen。或者更好的,而是采用了LinearLayout作为父母你的布局,你为什么不使用GridViewRecyclerView?用户将能够向下滚动,如果没有他们的设备上有足够的空间