2017-05-02 7 views
-1

동적으로 레이아웃을 만들고 싶습니다. 나 자신을 시도했지만 원하는 출력을 얻을 수 없습니다. 안 드 로이드에 새로운입니다, 여기 내 XML 코드입니다. 여기 android에서 동적 레이아웃을 만드는 방법

  <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:background="@drawable/box_sh1"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#f4f4f4" 
       android:weightSum="100"> 

       <Linear Layout 
        android:layout_width="0dp" 
        android:layout_weight="75" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:id="@+id/yeardetail" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="April 2010 to June 2012" 
         android:layout_marginTop="5dp" 
         android:textColor="#666" 
         android:textSize="14sp"/> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_weight="25" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:gravity="right"> 
        <Button 
         android:layout_width="25dp" 
         android:layout_height="25dp" 
         android:layout_marginRight="5dp" 
         android:background="@drawable/ic_action_edit"/> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 

보거나 이상의 주요 활동의 liniearlayout에 추가 row_layout을 팽창보다 .. 보이는 링크가 정확히 내가

enter image description here

답변

0

가 런타임에 추가 할 row_layout를 생성 할 것입니다

LinearLayout llGetQuote = (LinearLayout) mview.findViewById(R.id.llGetQuote); 

LayoutInflater li = LayoutInflater.from(getActivity()); 
View row = li.inflate(R.layout.row_layout, null); 
llGetQuote.addView(row); 

보기를 제거를 위해

당신이 당신의 답변에 대한 태그

imgDelete.setTag(i); 
imgDelete.setOnClickListener(CheckInActivity.this); 

같은 // 온 클릭 스위치의 경우

case R.id.imgDelete: 
     //here you get pos of view 
     pos = (int) v.getTag(); 

     //remove view code 
break; 
+0

감사를 설정할 수 있습니다 Clicklistner

를 추가하십시오. 하지만 레이아웃을 팽창시키는 것이 해결책이 아닌 것 같아서 나는 당신을 얻지 못하고 있습니다. – begginer

+0

하지만 원하는만큼보기를 추가 할 수 있습니다 .. 원하는 것이 무엇인지 설명 할 수있는 해결책이 아니라면 .. ?? –

+0

이제 여러 레이아웃을 확장 할 수있게되었습니다. 하지만 어떻게 내 레이아웃을 편집하고 삭제할 수 있도록 레이아웃에 동적 ID를 할당 할 수 있습니까? 내 레이아웃이 목록보기가 아닙니다. 그것은 간단한 활동이며 버튼 클릭에 대한 응답을 얻고 있습니다. – begginer

관련 문제