android dp大小用于LinearLayout [英] android dp size for LinearLayout

查看:61
本文介绍了android dp大小用于LinearLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向LinearLayout添加一些居中的元素(例如textViews或按钮).如果我使用android:layout_width ="fill_parent",则在平板电脑等大屏幕上,按钮可能太大.因此,我正在考虑限制大屏幕上的宽度.

I want to add some centered elements to a LinearLayout(like textViews or buttons). If I use android:layout_width="fill_parent" the button can be too big on a large screen like a tablet. So I am thinking to limit the width on larger screens.

我用这个

      <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical" >

        <LinearLayout android:orientation="vertical"

             android:layout_width="310dp"
             android:layout_height="fill_parent"
             android:paddingBottom ="60dp"
             android:paddingTop ="10dp"
             android:paddingLeft ="5dp"
             android:paddingRight ="5dp"
             android:id="@+id/linear_id"

             >


             ...............


        </LinearLayout>
    </LinearLayout>

从我看到的Android最小屏幕尺寸为320dp 此布局可以在任何小屏幕上正常显示,或者您认为某些设备上可能有问题吗?我将宽度设置为310dp,总填充为10dp,因此总宽度应为320dp.

From what I see the smallest screen size for Android is 320dp This layout will be displayed ok on any small screen or do you think I could have problems on some devices? I have set the width to 310dp and the total padding is 10dp so in total it should be 320dp.

谢谢

推荐答案

sdp (可扩展dp)替换 dp .这与屏幕尺寸成比例.它可以帮助您支持多个屏幕.

Replace dp with sdp(scalable dp). This scales with the screen size. It can help you with supporting multiple screens.

将此依赖项添加到gradle中.

Add this dependency in your gradle.

compile 'com.intuit.sdp:sdp-android:1.0.2'

像这样使用: android:paddingLeft ="@dimen/_5sdp"

还使用match_parent代替LinearLayoutHeight/Width

希望这对您有帮助....:):)

Hope this will help you.... :) :)

这篇关于android dp大小用于LinearLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆