zoukankan      html  css  js  c++  java
  • Android开发点滴

    问题描述:

    如何使按钮水平垂直居中且始终占据屏幕宽度一半

    效果如下:

    竖屏:

    横屏:

    解决方案:

    使用线性布局,指定线性布局的总权重(weightSum)为1, 指定按钮的权重为其一半即0.5

    布局代码如下:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF"
        android:gravity="center"
        android:orientation="horizontal"
        android:weightSum="1">
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="Click me"/>
    </LinearLayout>
  • 相关阅读:
    杨辉三角
    手动实现md5加密
    戳气球
    重构字符串
    四数相加 II
    背包问题 II
    组合总和 IV
    背包问题 V
    背包问题
    Win 10安装Python及环境变量配置
  • 原文地址:https://www.cnblogs.com/davidgu/p/5345978.html
Copyright © 2011-2022 走看看