2013-12-19 25 views
-1

我想为所有Android设备进行友好的设计。我使用导航抽屉为图像1上的智能手机进行了设计。我还希望在不使用导航抽屉的情况下为图像2上的平板设备进行设计。我怎样才能做到这一点?我是否需要以编程方式检测设备,如果是Tablet设备,我将使用Tablet设备的替代布局?Android平板电脑用户界面问题

这是我对平板电脑的布局(文件夹布局sw600dp),而不使用左抽屉:

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<LinearLayout 
    android:id="@+id/content" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<ListView 
    android:id="@+id/left_list" 
    android:listSelector="@drawable/state_listview_left" 
    android:choiceMode="singleChoice" 
    android:background="@color/white" 
    android:layout_gravity="start" 
    android:layout_width="300dp" 
    android:layout_height="match_parent" > 
</ListView> 

<LinearLayout 
    android:id="@+id/content_frame" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
    android:id="@+id/llBasketBarCenter" 
    style="@style/StyleInfoPanelBasket" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView1" 
       style="@style/StyleBarText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/payable" /> 

      <TextView 
       android:id="@+id/tvCenterPanelSum" 
       style="@style/StyleBarSum" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/textView1" /> 

      <TextView 
       android:id="@+id/tvCenterPanelSumCoins" 
       style="@style/StyleBarCoins" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@+id/tvCenterPanelSum" 
       android:layout_toRightOf="@+id/tvCenterPanelSum" /> 

      <TextView 
       android:id="@+id/tvCenterPanelSumValue" 
       style="@style/StyleBaCurrency" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignBaseline="@+id/tvCenterPanelSum" 
       android:layout_toRightOf="@+id/tvCenterPanelSumCoins" 
       android:text="@string/currency" /> 

      <RelativeLayout 
       style="@style/StyleCartIcon" 
       android:layout_toRightOf="@+id/tvCenterPanelSumValue" 
       android:layout_centerVertical="true"> 

       <TextView 
        android:id="@+id/tvCountInCart" 
        style="@style/StyleCartCount" 
        android:layout_alignParentRight="true" /> 

      </RelativeLayout> 

      <TextView 
       android:id="@+id/textView4" 
       style="@style/StyleTextNext" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:clickable="true" 
       android:onClick="onGoToTheBasketClick" 
       android:text="@string/in_basket" /> 

</RelativeLayout> 

</LinearLayout> 
</LinearLayout> 

<ListView 
    android:visibility="gone" 
    android:id="@+id/left_drawer" 
    android:listSelector="@drawable/state_listview_left" 
    android:choiceMode="singleChoice" 
    android:background="@color/white" 
    android:layout_gravity="start" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
</ListView> 

<LinearLayout 
    android:background="@color/white" 
    android:id="@+id/right_drawer" 
    android:layout_gravity="end" 
    android:layout_width="600dp" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

</LinearLayout> 

[在这里输入的形象描述] [1]

这里我的布局为其他设备使用左侧抽屉:

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<LinearLayout 
    android:id="@+id/content_frame" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
    android:id="@+id/llBasketBarCenter" 
    style="@style/StyleInfoPanelBasket" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView1" 
       style="@style/StyleBarText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/payable" /> 

      <TextView 
       android:id="@+id/tvCenterPanelSum" 
       style="@style/StyleBarSum" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/textView1" /> 

      <TextView 
       android:id="@+id/tvCenterPanelSumCoins" 
       style="@style/StyleBarCoins" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@+id/tvCenterPanelSum" 
       android:layout_toRightOf="@+id/tvCenterPanelSum" /> 

      <TextView 
       android:id="@+id/tvCenterPanelSumValue" 
       style="@style/StyleBaCurrency" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignBaseline="@+id/tvCenterPanelSum" 
       android:layout_toRightOf="@+id/tvCenterPanelSumCoins" 
       android:text="@string/currency" /> 

      <RelativeLayout 
       style="@style/StyleCartIcon" 
       android:layout_toRightOf="@+id/tvCenterPanelSumValue" 
       android:layout_centerVertical="true"> 

       <TextView 
        android:id="@+id/tvCountInCart" 
        style="@style/StyleCartCount" 
        android:layout_alignParentRight="true" /> 

      </RelativeLayout> 

      <TextView 
       android:id="@+id/textView4" 
       style="@style/StyleTextNext" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:clickable="true" 
       android:onClick="onGoToTheBasketClick" 
       android:text="@string/in_basket" /> 

</RelativeLayout> 


</LinearLayout> 

<ListView 
    android:id="@+id/left_drawer" 
    android:listSelector="@drawable/state_listview_left" 
    android:choiceMode="singleChoice" 
    android:background="@color/white" 
    android:layout_gravity="start" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
</ListView> 

<LinearLayout 
    android:background="@color/white" 
    android:id="@+id/right_drawer" 
    android:layout_gravity="end" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

</LinearLayout> 

+2

在人们协助之前,你需要发布你已经尝试过的东西,否则问题将被降低。 (我不downvote问题fyi,所以这不是我) – OceanLife

+0

使用相对布局将为您节省一些时间 – Hitman

+0

感谢您的意见。我真的不知道我必须在询问之前输入我所尝试的所有代码。我纠正了我的错误。 – Denis

回答

0

你可以做这样的事情在你的清单来决定您想要让您的应用

<supports-screens 
     android:largeScreens="false" 
     android:normalScreens="false" 
     android:smallScreens="false" 
     android:xlargeScreens="true" /> 
1

最好的做法是使用不同的布局为平板电脑和智能手机,由于不同尺寸的智能手机(兆,等等)和平板电脑(迷你等)我最好说,使用不同的布局将是一个很好的做法。检查手机和平板电脑与此代码示例。

if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_LARGE) == Configuration.SCREENLAYOUT_SIZE_LARGE ||(getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_XLARGE) == Configuration.SCREENLAYOUT_SIZE_XLARGE){ 
      //in tablet 
     } else { 
      //in Phone 

     }