0
단추 안에 3 개의 텍스트 뷰가있는 framelayout을 만들었습니다. 나는 이것을 복제하고 자바 프로그램을 통해 동적으로 추가하려고한다.프레임 레이아웃을 동적으로 생성하고 추가하십시오.
동일한 코드가 첨부되어 있습니다. 내가 3 프레임 레이아웃을 원하는
FrameLayout f2 = (FrameLayout)findViewById(R.id.frameLayout2);
FrameLayout f3;
f3 = f2;
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, R.id.frameLayout2);
f3.setLayoutParams(p);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:id="@+id/frameLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:layout_width="319dp" android:layout_height="130dp"/>
<TextView android:id="@+id/textView1" android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:layout_height="wrap_content" android:text="@string/app_name"/>
<TextView android:id="@+id/textView2"
android:layout_gravity="center_horizontal"
android:layout_marginTop="45dp"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name"/>
<TextView android:id="@+id/textView3"
android:layout_gravity="center_horizontal"
android:layout_marginTop="75dp"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name"/>
</FrameLayout>
<FrameLayout android:id="@+id/frameLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/frameLayout1">
<Button android:layout_width="319dp" android:layout_height="130dp"/>
<TextView android:id="@+id/textView4" android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:layout_height="wrap_content" android:text="@string/app_name"/>
<TextView android:id="@+id/textView5"
android:layout_gravity="center_horizontal"
android:layout_marginTop="45dp"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name"/>
<TextView android:id="@+id/textView6"
android:layout_gravity="center_horizontal"
android:layout_marginTop="75dp"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name"/>
</FrameLayout>
</RelativeLayout>
이 중복에 의해 주어진 마지막에 추가의 자바 코드는 두 번째 두 번째 아래에 배치하지만,이 코드를 실행한다 프레임 레이아웃도 보이지 않습니다. 아무도 내가 잘못 가고 있다고 말할 수 있습니까?
이것은 java입니다. f3 = f2를 작성하면 f3에서 f2를 참조하기 때문에 중복되지 않습니다. 확인 http://stackoverflow.com/questions/9807650/dynamically-cloning-a-linearlayout-in-android –
안녕하세요, 회신 해 주셔서 감사합니다, framelayouts이 작동합니까 ?? 내 말은, 전체 상대 레이아웃을 복제하고 싶지만 세그먼트 만 복제하고 싶지는 않습니다. – rafavinu
그럴 것 같아요. –