我有自定义编码的布局来容纳所有的孩子。下面是代码:对齐自定义LinearLayout中的对象?
public abstract class ItemView extends LinearLayout{
private ImageView icon;//cell icon
public static final int iconID=12345;
private Button accessorButton;//this will not be button ?
public static final int accessorID=54321;
public ItemView(Context context) {
super(context);
}
public void arrange(){
}
public void setView(Context context){
int l=super.getLeft();
int r=super.getRight();
int t=super.getTop();
int b=super.getBottom();
icon=new ImageView(context);
icon.setImageResource(R.drawable.star);
addView(icon);
accessorButton=new Button(context);
accessorButton.setText("accessor");
addView(accessorButton);
// icon.layout(l+5, t+5, l+100, b-5);
//accessorButton.layout(r-100, t+5, r-10, b-5);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
super.onLayout(changed, l, t, r, b);
}
}
,我有孩子的布局,其中之一是:
public class ItemPlainView extends ItemView{
private TextView text;
public ItemPlainView(Context context) {
super(context);
setView(context);
}
public void setView(Context context){
super.setView(context);
text=new TextView(context);
text.setText("plain view text");
addView(text);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
super.onLayout(changed, l, t, r, b);
}
public TextView getText() {
return text;
}
public void setText(TextView text) {
this.text = text;
}
@Override
public void arrange() {
// TODO Auto-generated method stub
}
}
当我运行它自然给了我一个星形图标,按钮,之后一个TextView代码。我需要替换和调整我的对象。在这个例子中,我需要将星形图标放在最左边的TextView中间,我的按钮放在最右边。考虑到这种层次观点,我该怎么做?
感谢
我不明白为什么您没有XML文件中的布局?没有什么是你正在做的,你现在无法用XML做。 – dymmeh 2011-06-16 15:23:21
我在选择中创建了我的布局和内部视图,其中有很多,我需要在运行时设置所有内容。此外,我还要以分层方式设置这些布局。我认为这会给我带来很大的安慰,编码 – ikbal 2011-06-16 15:30:38