【问题标题】:android dp size for LinearLayoutLinearLayout 的 android dp 大小
【发布时间】:2016-10-26 12:25:49
【问题描述】:

我想在 LinearLayout 中添加一些居中的元素(如 textViews 或按钮)。如果我使用 android:layout_width="fill_parent" 按钮在平板电脑等大屏幕上可能太大。所以我想限制大屏幕的宽度。

我用这个

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

谢谢

【问题讨论】:

  • 你试过 max-width 了吗?
  • 如果您想将按钮大小限制为屏幕的一半或某个百分比,请在布局中使用权重。
  • 感谢您的回答,但布局看起来不错。我只是问我是否会在某些手机上遇到问题(布局显示不正确)。只有当我遇到问题时,我才会更改布局

标签: android android-linearlayout


【解决方案1】:

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

在你的 gradle 中添加这个依赖项。

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

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

LinearLayoutHeight/Width中也使用match_parent而不是fill_parent

希望这会对你有所帮助.... :) :)

【讨论】:

    猜你喜欢
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 2014-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多