zoukankan      html  css  js  c++  java
  • 安卓 垂直方向上按比例布局

    下面是一个小小的例子,我弄了半天才把它弄好的。我要实现的是,上面一个按钮等屏宽,剩下的区域全部给EditText。

    有下面几个关键属性要注意。

    1、布局容器选的是LinearLayout

    2、方向选择为垂直的 android:orientation="vertical"

    3、对于两个控件来说, 其layout_width属性就必须设置为match_parent。

    4、按钮的android:layout_height设置为wrap_content。

        EditText的layout_height设置为“0dp”,但layout_weight设置为1-------->1指占用剩下高度的所有空间。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <Button
            android:id="@+id/button_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Show Result"
            />
    
        <EditText
            android:id="@+id/input_message"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            />
    
    </LinearLayout>

       实现效果如下:

  • 相关阅读:
    HDU 1010 Tempter of the Bone
    HDU 4421 Bit Magic(奇葩式解法)
    HDU 2614 Beat 深搜DFS
    HDU 1495 非常可乐 BFS 搜索
    Road to Cinema
    Sea Battle
    Interview with Oleg
    Spotlights
    Substring
    Dominating Patterns
  • 原文地址:https://www.cnblogs.com/kanite/p/6038923.html
Copyright © 2011-2022 走看看