简体   繁体   中英

layouts for different screen sizes android

I'm making an app that looks different for different screen sizes ,

however doing the seperation by screen size (small, medium, large, xlarge) doesn't quite do the job. because setting it to large give the same layout for my 5.5' oneplus one and my HTC sensation XL which is 4.3' I think.

Is there any way to make it for the screen size, not the resolution ?

Thanks

Edit to further explain my issue

layout on my Oneplus One

layout on my HTC

The pictures shows the layouts on these screens, I think it's difficult to make it look good on the smaller screen, that is why I want to make a separate layout for smaller screen.

my XML code

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:src="@drawable/ic_logo"

        />

    <GridLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/ic_appbg"
        android:padding="20dp">

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_column="1"
            android:layout_row="1"
            android:src="@drawable/ic_services" />

        <TextView
            android:layout_column="1"
            android:layout_gravity="center"
            android:layout_row="2"
            android:text="@string/Services"
            android:textColor="@color/colorSecondaryText"

            />

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"

            android:layout_column="2"
            android:layout_row="1"
            android:src="@drawable/ic_send_balance" />

        <TextView
            android:layout_column="2"
            android:layout_gravity="center"
            android:layout_row="2"
            android:text="@string/sendBalance"
            android:textColor="@color/colorSecondaryText"

            />


        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_column="3"
            android:layout_row="1"
            android:src="@drawable/ic_call_me" />

        <TextView
            android:layout_column="3"
            android:layout_gravity="center"
            android:layout_row="2"
            android:text="@string/pay4me"
            android:textColor="@color/colorSecondaryText"

            />

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_column="1"
            android:layout_row="3"
            android:src="@drawable/ic_damage_vou" />

        <TextView
            android:layout_width="100dp"
            android:layout_column="1"
            android:layout_row="4"
            android:gravity="center"
            android:text="@string/damaged"
            android:textColor="@color/colorSecondaryText"

            />

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_column="2"
            android:layout_row="3"
            android:onClick="balance"
            android:src="@drawable/ic_check_balance" />

        <TextView
            android:layout_column="2"
            android:layout_gravity="center"
            android:layout_row="4"
            android:text="@string/checkBalance"
            android:textColor="@color/colorSecondaryText"

            />


        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_column="3"
            android:layout_row="3"
            android:src="@drawable/ic_setting" />

        <TextView
            android:layout_column="3"
            android:layout_gravity="center"
            android:layout_row="4"
            android:text="@string/action_settings"
            android:textColor="@color/colorSecondaryText" />


    </GridLayout>
</LinearLayout>

Its may not be a good method anyway, Fetch the device height and with in the splash page or the 1st page. In all your inner activities write different layout and put the set content view in a condition according to your desired size option.

eg:-

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (size > 5) {
            setContentView(R.layout.activity_one);
        } else {
            setContentView(R.layout.activity_two);
        }
    }

;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM