레이아웃 관련 문제.프로그래밍 방식으로 선형 하위 레이아웃을 관리하는 방법은 무엇입니까?
동적으로보기를 추가하려고합니다.
논리 코드 :
linear1 = (LinearLayout) findViewById(R.id.parent);
linear2 = (LinearLayout) findViewById(R.id.chiled);
int len = 4;
for (int i = 1; i <= len; i++) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
params1.gravity = Gravity.RIGHT;
final int id_txt;
ImageView iv = new ImageView(this);
iv.setId(i);
id_txt = iv.getId();
iv.setBackgroundResource(R.drawable.ic_launcher);
linear1.addView(iv, params);
iv = ((ImageView) findViewById(id_txt));
for (int j = 1; j < 2; j++) {
final int id_;
Button btn = new Button(this);
btn.setId(i);
id_ = btn.getId();
btn.setText("button " + id_);
linear2.addView(btn, params1);
btn = ((Button) findViewById(id_));
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(v.getContext(),
"Button clicked index = " + id_,
Toast.LENGTH_SHORT).show();
}
});
}
// btn.setBackgroundColor(Color.rgb(70, 80, 90));
// linear1.addView(txt, params);
// params.addRule(RelativeLayout.RIGHT_OF, txt.getId());
iv.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(view.getContext(),
"text clicked index = " + id_txt,
Toast.LENGTH_SHORT).show();
}
});
}
}
XML 코드 : 아이 뷰의 동적에서
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/chiled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
내가 부모보기에 이미지를 추가 할
두 개의 버튼을 누릅니다.
I는
Android heterogeneous gridview like pinterest?
그것은 같아야 이러한 타입 뷰 형태를 만들기 위해 고무
같은전류 출력
0,123,516로서어디에 문제가 있는지 알 수 없습니다. 내가 코드에서 레이아웃을 볼 수 경우
한 이상한 문제를 내가 각 레이아웃 android:orientation="horizontal"
을 보여줍니다 개요에서 볼 경우 다음의 나에게 android:orientation="vertical"
를 보여줍니다 내 편집기 지금 직면하고있다. 그게 어떻게 가능해 ? 저를 탈 수평 LinearLayout chiled
이후
아니요. 몇 가지 다른 입술도 있습니다. –
그런 다음 'getChildCount() - 1'과 같은 특정 인덱스가있는 하위 항목을 추가하십시오. – Greeny