• 使用weight属性实现视图的居中显示


    有的时候我们开发一个产品的时候需要让其中某个控件的宽度或高度占据其父容器的宽度或高度的一半显示,这个时候由于设备尺寸的限制,做到在每个设备上都具有同样的效果的话,我们就需要用到weightSum属性和layout_weight属性。

    具体的实现过程分析如下:

    首先为父容器指定一个weightSum,然后为其子控件的layout_weight属性值设为weightSum的一半,这个时候,就实现了占据其一半的效果。

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     android:layout_width="fill_parent"
     3     android:layout_height="fill_parent"
     4     android:background="#ffffff"
     5     android:gravity="center"
     6     android:orientation="horizontal"
     7     android:weightSum="1" >
     8 
     9     <Button
    10         android:layout_width="0dp"
    11         android:layout_height="wrap_content"
    12         android:layout_weight="0.5"
    13         android:text="@string/activity_main_click_me" />
    14 
    15 </LinearLayout>
  • 相关阅读:
    BZOJ 1630/2023 Ant Counting 数蚂蚁
    BZOJ 3997 组合数学
    BZOJ 2200 道路与航线
    BZOJ 3181 BROJ
    BZOJ 4011 落忆枫音
    BZOJ 4027 兔子与樱花
    vijos 1741 观光公交
    vijos 1776 关押罪犯
    vijos 1780 开车旅行
    5、异步通知机制
  • 原文地址:https://www.cnblogs.com/zhjsll/p/4113664.html
Copyright © 2020-2023  润新知