简体   繁体   English

android不同屏幕尺寸的布局

[英]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. 但是按屏幕尺寸(小,中,大,xlarge)进行分隔并不能完全解决问题。 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. 因为将其设置为大尺寸,可以为我的5.5英寸oneplus和我的HTC感觉XL提供相同的布局(4.3英寸)。

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 Oneplus One上的布局

layout on my HTC 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 我的XML代码

    <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);
        }
    }

;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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