【问题标题】:FrameLayout and percentage of screenFrameLayout 和屏幕百分比
【发布时间】:2013-04-03 21:09:39
【问题描述】:

我有一个 FrameLayout,上面显示了一个 LinearLayout 我的意图是这个LinearLayout总是占据屏幕的33%……但我做不到。 我尝试使用“dp”,但当然,结果因密度而异。 如果它们是两个 LinearLayout,如果我可以使用 layout_weight = ".33" 和 layout_weight = ".67" 但是 FrameLayout 在其中之一中使用。

希望能解释清楚

提前致谢

问候

【问题讨论】:

    标签: android android-linearlayout percentage android-framelayout


    【解决方案1】:

    自 2015 年 8 月起,您可以使用原生布局 PercentFrameLayout 和 PercentRelativeLayout 执行此类布局。从第 23 版开始,两者都在 Android 支持库中可用。

    【讨论】:

      【解决方案2】:

      你可以试试这样的。 第一层是 ImageView,第二层有两个线性布局。

      <FrameLayout
          android:layoit_height="match_parent"
          android:layout_width="match_parent">
          <ImageView
              android:layoit_height="match_parent"
              android:layout_width="match_parent"
              android:image="@drawable/screen_image"/> //blue image whith white "screen"
      
          <LinearLayout
              android:layoit_height="match_parent"
              android:layout_width="match_parent">
              <LinearLayout
                  android:layoit_height="0dp"
                  android:layout_weight=".67"
                  android:layout_width="match_parent"
                  android:background="#00000000"/>
      
              <LinearLayout
                  android:layoit_height="0dp"
                  android:layout_weight=".33"
                  android:layout_width="match_parent"
                  android:background="#44FF0000"> //33% layout
      
                  //children for 33% layout here
      
              </LinearLayout>
          </LinearLayout>
      
      </FrameLayout>
      

      【讨论】:

      • 问题是我不需要顶部的LinearLayout:(
      • 在上部布局中使用值“invisible”,可以工作。谢谢;)
      • @MiguelC 我希望我的解决方案对你有用。
      猜你喜欢
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多