layout_height / ayout_width = 0dp

When a LinearLayout is vertical, then the layout_weight will effect the height of the child Views (ListView). Setting the layout_height to 0dp will cause this attribute to be ignored. The reason to want to ignore the attribute is that if you didn’t ignore it, it would be used to calculate the layout which uses more CPU time.

This is usually used when having many views inside a linearlayout and have set android:layout_weight=”1″ in order both views to take equal space.

layout_weight体验(实现按比例显示)

按比例显示LinearLayout内各个子控件,需设置android:layout_width=”0dp”,如果为竖直方向的设置android:layout_height=”0dp”。在这种情况下某子个控件占用LinearLayout的比例为:本控件weight值 / LinearLayout内所有控件的weight值的和。

这三个TextView是按照1:2:3的比例进行显示的,这样看来似乎可以实现按照比例显示了,但是有个问题,如果TextView内的文本长度一同那么较长文本的TextView会宽度会有所增加,见下面配置及效果:

onfinishinflate 什么时候调用

onFinishInflate 当View中所有的子控件均被映射成xml后触发
onSizeChanged 当view的大小发生变化时触发

构造方法和onFinishInflate都是在setContentView(R.layout.buttonwaveview); 就开始执行了,然后再回执行onCreate后面的代码

自定义组合组件 大多有两种
1、在onSizeChanged里面写
2、在onFinishInflate里面写
onSizeChanged 
其实 上面的代码onSizeChanged是不会执行 ,它是在view大小发生改变时才执行的,所有代码都是在onSizeChanged里面写的 但是onSizeChanged不执行怎么办?所以在构造方法里面,设置了背景图片 认为的改变view 这样就可以调用onSizeChanged了

setBackgroundResource(R.drawable.tabswitcher_long);

onFinishInflate 

这个里面写也是可以的 但是 有一个问题
假如说 我在Activity里面 需要设置自定义组件ButtonWaveView 的一些变量,而且这些变量(例如 width,height)是必须在addview前面调用的
我们的set方法肯定是写在onCreat里面的 但是前面我们也看到了 onFinishInflate是先于onCreat()执行的  这时 我们的程序就有问题了

解决方法有两个

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: