2

I have got a project that implement tablet version of an app. this app has only portrait mode without landscape mode support. so my approach would be implementation for both in tablet.

However, you guys all know that android has different type of devices and android version. how to make sure that my tablet app will work for every tablet devices. Also UI, what is the best practice to do in tablet? how can I make sure my app layout is fit in all devices? What kind of UI framework would be useful for developing android tablet?

4

1 回答 1

5

你必须使用片段。所以你的应用可能看起来像这样:

在此处输入图像描述

  • 创建一个布局,一个用于手机,一个用于平板电脑。

布局/main.xml:

<LinearLayout
android:id="@+id/handset"
[...]
>
</LinearLayout>

布局大/sw400dp:

<LinearLayout 
  [...]
  >

    <fragment android:name="com.bla.bla.FirstFragment"
              android:id="@+id/first_fragment"
              [...]
              />

     <fragment android:name="com.bla.bla.SecondFragment"
              android:id="@+id/second_fragment"
              [...]
              />

</LinearLayout>
  • 现在在您的 FragmentActivity 中检查这一点:

if (findViewById(R.id.handset) != null) {
    // it's a handset device and you can add a Fragment to this View
    }

 FirstFragment firstFragment = new FirstFragment();
 getSupportFragmentManager().beginTransaction().add(R.id.handset, firstFragment).commit();
  • 如果R.id.handset返回 null 那么它是一个平板电脑,在这种情况下,静态添加的 Fragments 将由它们的 Fragments 类处理。
于 2013-01-18T15:32:05.150 回答