すべての子を保持するカスタム コード レイアウトがあります。コードは次のとおりです。
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);
}
}
子レイアウトがあります。そのうちの1つは次のとおりです。
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 に星のアイコンを配置し、一番右側にボタンを配置する必要があります。この階層的なビューを考えると、どうすればそれを行うことができますか?
ありがとう