2014-10-13 3 views
0

Layout을 추가하려고합니다. 처음으로 내 뷰를 만들 때 레이아웃이 멋지게 추가됩니다. 이는 inflate 및 addView가 잘 작동 함을 의미합니다. 하지만 버튼을 클릭하여 두 번째로 프로세스를 수행하고 동일한 시각에 다른 뷰를 추가 할 수는 있지만 뷰는 첫 번째 뷰 위에 추가됩니다.부풀려진 LinearLayout에 뷰 추가

조각 :

// onCreateView, I bind the container with his LinearLayout 
mLnPricing = (ViewGroup) mRootView.findViewById(R.id.lnPricing); 

//some stuff 

private void createPriceBlock() { 

    mParent = LayoutInflater.from(getActivity()).inflate(
      R.layout.block_pricing, null); 
    //binding some views 
    mIbAddPricing.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      createPriceBlock(); 
     } 
    }); 
    mLnPricing.addView(mParent,0); 
} 

block_pricing.xml :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

//some text fields 

</LinearLayout> 

main_lauyout.xml가 :

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

//some controllers 

    <LinearLayout 
     android:id="@+id/lnPricing" 
     style="@style/addLabels.AppTheme" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" /> 




</ScrollView> 

내 코드로 잘못 알고 있지만, 일부 이상한위한하지 않습니다 같은 코드가 다른 프로젝트에서 작동하는 이유.

내가 원하는 것 : 0 위치에 새보기를 추가하고 다른보기를 아래로 이동하십시오.

나는 무엇을 : 뷰는 뷰

+0

'CustomAdapter'와'listView'와'custom view'에 더 잘 어울립니다. – Panther

+0

mLnPricing.requestLayout(); –

+0

@MikeM. 고마워. 나는 오리 엔테이션을 오버라이드하는 것을 정말로 놓쳤다. – 113408

답변

1

있는 LinearLayout의 기본 방향이 수평 아래에 생성 된 미리보기 하나의 위쪽의 빈 공간에 추가 할 수 있습니다. 새로운 뷰가 추가되고있는 LinearLayout의 방향을 지정하지 않았기 때문에, 낡은 뷰가 화면 밖으로 벗어나 오른쪽에 밀리고 있습니다. LinearLayout 태그 lnPricingandroid:orientation="vertical"을 추가하십시오.