在自定义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中放置星形图标,在最右边的地方放置我的按钮。考虑到这种分层视图,我该怎么做?
谢谢
没有找到相关结果
已邀请:
2 个回复
豆兢
,您可能想选择
之前的
还是
之后的
和
那么您的java类只需要在
之后的
中调用
比您拥有的要容易得多。您也可以根据需要轻松地安排任何这些项目。看到LinearLayout,您也可以使用TableLayout,但我认为对于大多数情况而言,它们太复杂了。
购藏盗码韦