A good approach to Android app development for Android

I have a project that implements a tablet version of an application. this app only has portrait mode without support for landscape mode. so my approach will be implemented as for tablets.

however, you guys all know that Android has different device types and Android version. how to make sure the tablet app will work on all tablet devices. See also UI, what is the best thing to do on a tablet? How can I make sure my app layout is suitable for all devices? what UI structure would be useful for android tablet development?

Many thanks!!! I would be grateful for an exchange of experience.

Regards justicepenny

+3


source to share


1 answer


You have to use fragments. Thus, your application might look like this:

enter image description here

  • Create a layout, one for the phone and one for the tablet.

layout /main.xml:

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

      

layout large / sw 400dp:



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

      

  • Now check this in your FragmentActivity:

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

 FirstFragment firstFragment = new FirstFragment();
 getSupportFragmentManager().beginTransaction().add(R.id.handset, firstFragment).commit();

      

  • If it R.id.handset

    returns null, then this is a pill, in which case the statically added fragments will be processed by their Fragments class.
+5


source







All Articles