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>



  • 相关阅读:
    【转】VS2010中 C++创建DLL图解
    [转]error: 'retainCount' is unavailable: not available in automatic reference counting mode
    [转]关于NSAutoreleasePool' is unavailable: not available in automatic reference counting mode的解决方法
    【转】 Tomcat v7.0 Server at localhost was unable to start within 45
    【转】Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If
    【转】SVN管理多个项目版本库
    【转】eclipse安装SVN插件的两种方法
    【转】MYSQL启用日志,和查看日志
    【转】Repository has not been enabled to accept revision propchanges
    【转】SVN库的迁移
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7084131.html
Copyright © 2011-2022 走看看