1. 如何设置了top和bottom ,可以使用
android:layout_width="match_parent"
android:layout_height="0dp"android:layout_weight="1" > 来占据剩余空间
2.去掉activity的默认title
在setContentView之前加上requestWindowFeature(Window.FEATURE_NO_TITLE);
3.LinearLayout 布局里边如果包含了ImageButton等子元素,如果想让layout自己处理时间监听,需要将其子元素的clickable 设置为false,否则,layout会将事件交给子元素处理。
4.如果Fragment中无法加载layout布局,可能是R文件导错了
5.自定义控件若需要在xml文件中使用,就必须重写带如上两个参数的构造方法。添加后即可正常使用了。
如:自定义listview后 要加上两个参数的构造方法,
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
不然报错:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android_activity/com.example.android_activity.MainActivity}: android.view.InflateException: Binary XML file line #118: Error inflating class com.example.android_activity.MyListView
......
Caused by: android.view.InflateException: Binary XML file line #118: Error inflating class com.example.android_activity.MyListView
6.得到自定义控件的高度和宽度
int w = View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED);
headview.measure(w, h);
int a = headview.getMeasuredHeight();