当前位置:编程学习 > wap >>

一个layout文件中有好多RelativeLayout,如何保证每一次只能选中一个呢,谢谢大家

如标题,谢谢大家的回复 --------------------编程问答-------------------- 通过ID啊 --------------------编程问答-------------------- 其实不大清楚楼主说的啥,一次选中一个是啥意思? --------------------编程问答-------------------- 不明白楼主说的是什么意思 --------------------编程问答--------------------
 LayoutInflater layout = LayoutInflater.from(this);
           View view = layout.inflate(R.layout.frame_setting, null);

我已经得出我的view,如何循环得到view里的RelativeLayout
谢谢 --------------------编程问答--------------------
引用 4 楼 qiuqingpo 的回复:
 LayoutInflater layout = LayoutInflater.from(this);
           View view = layout.inflate(R.layout.frame_setting, null);

我已经得出我的view,如何循环得到view里的RelativeLayout
谢谢


你要么用一个数组把这些layout 的id存起来,要么就用反射获得 --------------------编程问答-------------------- 这是要实现什么功能呢?给每个relativeLayout设置ID不就可以了么 --------------------编程问答--------------------
引用 6 楼 pengguohua1988 的回复:
这是要实现什么功能呢?给每个relativeLayout设置ID不就可以了么




引用 5 楼 siyehua 的回复:
Quote: 引用 4 楼 qiuqingpo 的回复:

 LayoutInflater layout = LayoutInflater.from(this);
           View view = layout.inflate(R.layout.frame_setting, null);

我已经得出我的view,如何循环得到view里的RelativeLayout
谢谢


你要么用一个数组把这些layout 的id存起来,要么就用反射获得

哈哈,看到了TM的一个样式,想练练手
想知道有没有一个能取到view下所有控件的方法,如果没有的话我只好一个个加找了 --------------------编程问答-------------------- 你的最外层应该是个FrameLayout、LinearLayout或者RelativeLayout,加入是LinearLayout,
那么可以采用遍历子View的方法:
LayoutInflater layout = LayoutInflater.from(this);
LinearLayout parentView = layout.inflate(R.layout.frame_setting, null);
for (int i=0; parentView.getChildCount(); ++i) {
    //这里的childView就是楼主所需的一个个的RelativeLayout
    View childView = view.getChildAt(i);
}
--------------------编程问答--------------------
引用 8 楼 ncepu307 的回复:
你的最外层应该是个FrameLayout、LinearLayout或者RelativeLayout,加入是LinearLayout,
那么可以采用遍历子View的方法:
LayoutInflater layout = LayoutInflater.from(this);
LinearLayout parentView = layout.inflate(R.layout.frame_setting, null);
for (int i=0; parentView.getChildCount(); ++i) {
    //这里的childView就是楼主所需的一个个的RelativeLayout
    View childView = view.getChildAt(i);
}


由于当前activity加载的是另我的布局,我这样放上去不起作用呢?你的可以不 --------------------编程问答--------------------
引用 9 楼 qiuqingpo 的回复:
Quote: 引用 8 楼 ncepu307 的回复:

你的最外层应该是个FrameLayout、LinearLayout或者RelativeLayout,加入是LinearLayout,
那么可以采用遍历子View的方法:
LayoutInflater layout = LayoutInflater.from(this);
LinearLayout parentView = layout.inflate(R.layout.frame_setting, null);
for (int i=0; parentView.getChildCount(); ++i) {
    //这里的childView就是楼主所需的一个个的RelativeLayout
    View childView = view.getChildAt(i);
}


由于当前activity加载的是另我的布局,我这样放上去不起作用呢?你的可以不

我的是可以的,什么另我的布局? --------------------编程问答--------------------
引用 10 楼 ncepu307 的回复:
Quote: 引用 9 楼 qiuqingpo 的回复:

Quote: 引用 8 楼 ncepu307 的回复:

你的最外层应该是个FrameLayout、LinearLayout或者RelativeLayout,加入是LinearLayout,
那么可以采用遍历子View的方法:
LayoutInflater layout = LayoutInflater.from(this);
LinearLayout parentView = layout.inflate(R.layout.frame_setting, null);
for (int i=0; parentView.getChildCount(); ++i) {
    //这里的childView就是楼主所需的一个个的RelativeLayout
    View childView = view.getChildAt(i);
}


由于当前activity加载的是另我的布局,我这样放上去不起作用呢?你的可以不

我的是可以的,什么另我的布局?


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.testhead);
initRelativeLayout();
}
private void initRelativeLayout()
{
            LayoutInflater layout = LayoutInflater.from(this);
            View view = layout.inflate(R.layout.frame_setting, null);
         // this.addContentView(view, null);
           RelativeLayout shakeLayout=(RelativeLayout)view.findViewById(R.id.vibrate_notify);
           TextView txtView=(TextView)view.findViewById(R.id.shake_title);
           txtView.setText("不想说太多");
          
}

在一个布局里,好像也改变不了另外一个layout里的控件的属性,另外显示怎么追当加当前布局? --------------------编程问答--------------------
引用 10 楼 ncepu307 的回复:
Quote: 引用 9 楼 qiuqingpo 的回复:

Quote: 引用 8 楼 ncepu307 的回复:

你的最外层应该是个FrameLayout、LinearLayout或者RelativeLayout,加入是LinearLayout,
那么可以采用遍历子View的方法:
LayoutInflater layout = LayoutInflater.from(this);
LinearLayout parentView = layout.inflate(R.layout.frame_setting, null);
for (int i=0; parentView.getChildCount(); ++i) {
    //这里的childView就是楼主所需的一个个的RelativeLayout
    View childView = view.getChildAt(i);
}


由于当前activity加载的是另我的布局,我这样放上去不起作用呢?你的可以不

我的是可以的,什么另我的布局?

少打了一个字哈,是另外一个布局文件 --------------------编程问答-------------------- View view = layout.inflate(R.layout.frame_setting, null);
这个不能为null吧。因为你要加到另外一个布局上面,所以要指定被添加布局的LayoutParams。 --------------------编程问答--------------------
引用 13 楼 birdfly12345 的回复:
View view = layout.inflate(R.layout.frame_setting, null);
这个不能为null吧。因为你要加到另外一个布局上面,所以要指定被添加布局的LayoutParams。

能不能再具体一点,不是太懂呢 --------------------编程问答-------------------- 为什么在同一个activity中不能修改另外一个layout文件中控件的属性
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,