zoukankan      html  css  js  c++  java
  • Android布局文件经验

    1.父控件中含有多个子控件时。往往遵循长子优先的原则,即长子假设非常大可能占满父空间。使次子们出局;
    2.如果TableLayout有2行,当中一行未设定列间长度比例。而还有一行设定了,则未设定行可能也会遵循设定行的列间长度比例;
    3.ImageView中的scaleType,对android:src="@drawable/logo"。而对android:background="@drawable/logo"可能不起作用;
    4.在某个区域(如TableLayout中某个单元格)显示某张超大的图片。希望图片总是自适应单元格而不是把单元格撑爆。解决方式:将单元格放在LinearLayout中,给LinearLayout设置android:layout_width="wrap_content"、android:orientation="horizontal"。给单元格设置layout_weight属性、不设置android:layout_width属性。



    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff">
    
        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/include1"
            android:background="#dedcd2"
            android:stretchColumns="*" >
    
            <TableRow
                android:layout_margin="0.5dip"
                android:background="#dedcd2" >
    
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:orientation="horizontal" >
    
                    <TextView
                        android:layout_height="fill_parent"
                        android:layout_margin="1dip"
                        android:layout_weight="2"
                        android:background="#ffffff"
                        android:text=""
                        android:textSize="12dp"
                        android:textStyle="bold" />
    
                    <TextView
                        android:layout_height="fill_parent"
                        android:layout_margin="1dip"
                        android:layout_weight="2"
                        android:background="#ffffff"
                        android:text=""
                        android:textSize="12dp"
                        android:textStyle="bold" />
                    
                    <!-- @drawable/right 为超大图片 -->
                    <ImageView
                        android:layout_height="fill_parent"
                        android:layout_margin="1dip"
                        android:layout_weight="1"
                        android:src="@drawable/right" />
    
                    <TextView
                        android:layout_height="fill_parent"
                        android:layout_margin="1dip"
                        android:layout_weight="2"
                        android:background="#ffffff"
                        android:text=""
                        android:textSize="12dp"
                        android:textStyle="bold" />
                </LinearLayout>
            </TableRow>
        </TableLayout>
    
    </RelativeLayout>
    
    
    
    1.父控件中含有多个子控件时。往往遵循长子优先的原则,即长子如果非常大可能占满父空间,使次子们出局;
    
    2.如果TableLayout有2行,当中一行未设定列间长度比例,而还有一行设定了,则未设定行可能也会遵循设定行的列间长度比例;
    
    3.ImageView中的scaleType,对android:src="@drawable/logo",而android:background="@drawable/logo",我就笨笨地犯了这个低级错误,导致错怪人家scaleType不起作用。
    
    3.在某个区域(如TableLayout中某个单元格)显示某张超大的图片,希望图片总是自适应单元格而不是把单元格撑爆。

    解决方式:将单元格放在LinearLayout中,给LinearLayout设置android:layout_width="wrap_content"、android:orientation="horizontal"。给单元格设置layout_weight属性、不设置android:layout_width属性。 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff"> <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/include1" android:background="#dedcd2" android:stretchColumns="*" > <TableRow android:layout_margin="0.5dip" android:background="#dedcd2" > <LinearLayout android:layout_width="wrap_content" android:layout_height="30dp" android:orientation="horizontal" > <TextView android:layout_height="fill_parent" android:layout_margin="1dip" android:layout_weight="2" android:background="#ffffff" android:text="" android:textSize="12dp" android:textStyle="bold" /> <TextView android:layout_height="fill_parent" android:layout_margin="1dip" android:layout_weight="2" android:background="#ffffff" android:text="" android:textSize="12dp" android:textStyle="bold" /> <!-- @drawable/right 为超大图片 --> <ImageView android:layout_height="fill_parent" android:layout_margin="1dip" android:layout_weight="1" android:src="@drawable/right" /> <TextView android:layout_height="fill_parent" android:layout_margin="1dip" android:layout_weight="2" android:background="#ffffff" android:text="" android:textSize="12dp" android:textStyle="bold" /> </LinearLayout> </TableRow> </TableLayout> </RelativeLayout>



  • 相关阅读:
    [项目管理]记一次外包过程遇到的“问题”以及“应对之道”
    [ZT]Web Standard and ASP.NET – Part1 XHTML Quick Start
    [前端技术]利用 try...catch 来跳出JQuery.each()
    [ZT]Use JQuery to adjust the iframe height
    [CSharp]复合格式化(Composite Formatting)
    [项目管理]关于项目的工期控制
    [CSharp]判断表达式为空的二元运算符
    MySoft.Data ORM组件之获取插入后的自增主键
    [前端技术]让iframe背景透明起来
    NSRunLoop
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7084131.html
Copyright © 2011-2022 走看看