Android布局总结和Android 9 patch 图片使用

一、布局的一些问题总结     

1、首先说下RelativeLayout布局,其实实现的效果就是按照元素的相对位置设置摆放位置,如果没有设置相关属性,例如above、belove等相关属性是默认是在屏幕的顶部,并且多个View互相叠放,后面的View会叠放在前面的View之上。根据这个特点,我们可以设置一下进度条之类的东东,比如下面的一个浏览器对话框,当访问网页是弹出对话框,网页结束是将对话框的view设置gone即可。

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
	android:id="@+id/webfrm"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:background="@color/bgcolor"
	android:orientation="vertical"
	xmlns:android="http://schemas.android.com/apk/res/android">
	<WebView
		android:id="@+id/webview1"
		android:layout_width="fill_parent"
		android:layout_height="fill_parent"></WebView>
	<RelativeLayout
		android:id="@+id/RelativeLayout01"
		android:layout_width="fill_parent"
		android:layout_height="fill_parent">
		<ProgressBar
			android:id="@+id/LoadingBar"
			android:indeterminate="true"
			android:visibility="visible"
			android:layout_centerInParent="true"
			android:minHeight="100px"
			android:minWidth="100px"
			android:layout_height="100px"
			android:layout_width="100px" />
	</RelativeLayout>
</AbsoluteLayout>

效果图预览:


2、FrameLayout的一些使用心得,之前项目中用的比较少,对她得认识也不深。

      Framlayout可以用来实现多种界面的切换。在TabHost中经常用到。

   

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TextView 
                android:id="@+id/textview1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is a tab" />
            <TextView 
                android:id="@+id/textview2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is another tab" />
            <TextView 
                android:id="@+id/textview3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is a third tab" />
    	</FrameLayout>
    </LinearLayout>
</TabHost>


当调用到那个view是将它显示出来即可。

 

二、Android 9 patch 工具的使用。

        所谓 9-patch drawables,就是将一个 drawable 按照定义的 4 个边缘的宽度大小切割成9个区域,包括4个角落,4条边缘和一个中心区域,当把这个 drawable 绘制到一个任意矩形区域时,drawable 的各个区域有不同的拉伸控制(角落不拉伸,横边横向拉伸,竖边竖向拉伸,中心区域横竖向都拉伸)。通常使用 9-patch drawable 一般是为了绘制出比较漂亮的带圆角背景,这样可以避免圆角及边缘被任意拉伸导致变形。

 

说明:①左边和顶部两条黑线选择拉伸的区域

            ②右边和底部选定content,既文本区域

效果图:

   

 

 参考:http://www.cnblogs.com/qianxudetianxia/archive/2011/04/17/2017591.html

            http://blog.csdn.net/xiaominghimi/article/details/6107837

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值