Android自定义Layout嵌套问题.
直接上代码吧:一直在纠结。。。求各位大神点破:
一、这是MainActivity:
二、这是MyActivity要显示的MyRelativeLayout
三、这是MyRelativeLayout对应的xml文件:
四、这是嵌套的MyLinearLayout:
五、这个嵌套MyLinear对应的xml文件:
问题是:
现在不现实嵌套的MyLinearLayout中的TextView。
一、这是MainActivity:
public class MainActivity extends Activity {
private MyRelativeLayout mRL;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRL=(MyRelativeLayout)LayoutInflater.from(this).inflate(R.layout.activity_main, null);
setContentView(R.layout.activity_main);
}
}二、这是MyActivity要显示的MyRelativeLayout
public class MyRelativeLayout extends RelativeLayout {
MyLinearLayout mLL;
private Context mContext;
public MyRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this.mContext=context;
// TODO Auto-generated constructor stub
}
@Override
public void onFinishInflate(){
super.onFinishInflate();
init();
}
public void init(){
mLL=(MyLinearLayout)this.inflate(mContext,R.layout.relative,null);
}
}三、这是MyRelativeLayout对应的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<com.example.viewtest.MyRelativeLayout 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"
>
<com.example.viewtest.MyLinearLayout
android:id="@+id/layout"
android:layout_width="200px"
android:layout_height="200px"
android:background="#ff0000">
</com.example.viewtest.MyLinearLayout>
<ImageView
android:layout_below="@id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</com.example.viewtest.MyRelativeLayout>四、这是嵌套的MyLinearLayout:
public class MyLinearLayout extends LinearLayout {
public MyLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
}五、这个嵌套MyLinear对应的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<com.example.viewtest.MyLinearLayout
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"
>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</com.example.viewtest.MyLinearLayout>问题是:
现在不现实嵌套的MyLinearLayout中的TextView。
...全文
相关推荐
安卓关系布局
安卓的关系布局方法,包括一些常用的空间以及方法等很多的使用
安卓表格布局实例
安卓表格布局,表格布局也是布局方法之一,是安卓入门的必要技能,通俗易懂的实例,欢迎下载
安卓下拉上拉刷新相关-安卓自带刷新控件SwipeRefreshLayout上拉加载更多自动刷新.rar
安卓自带刷新控件SwipeRefreshLayout 上拉加载更多 自动刷新.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
安卓开发-SwipeRefreshLayoutSample.zip.zip
安卓开发-SwipeRefreshLayoutSample.zip.zip
安卓Android源码——拖动Button显示效果.zip
安卓Android源码——拖动Button显示效果.zip


