2014-10-16 3 views
0

저는 뉴스 목록이있는 일종의 뉴스 응용 프로그램을 빌드하려고합니다. 탭하면 자세한 뉴스가 표시됩니다. 1. 휴대 전화가 세로 방향 인 경우 세부 정보는 다른 활동 에 표시됩니다. 2. 휴대 전화가 가로 방향 인 경우 세부 정보는 동일한 활동의 ​​세부 정보 레이아웃 조각에 뉴스 목록과 함께 표시됩니다. 특정 방향으로 만보기 그룹을 표시하려면

이 (가 '뉴스 목록'의 조각과 '세부 사항'의)

내가 뭘 달성 할 수없는 것은 세부 조각이 걸릴 공간을 제거하는 것입니다 - 내가 가로 모드에 있었던 경우 -에서 세로 모드.

이것은 활동 레이아웃 파일에서 조각의 컨테이너로 두 개의 빈 viewGroup을 언급했기 때문입니다.

각 방향에 대해 별도의 레이아웃을 만들고 싶지 않습니다.

비어있는 경우보기 그룹을 숨기거나 뺄 수있는 방법이 있습니까?

관련 코드 :

주요 활동의 XML :

<LinearLayout 
     android:id="@+id/news_list_container" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="0.4" 
     > 
     </LinearLayout> 

    <LinearLayout 
     android:id="@+id/details_container" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="0.6" 
     > 
     </LinearLayout> 




</LinearLayout> 

주요 활동 클래스 - 추가 조각 내 취향에 따라 :

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     //get orientation first 
     if(this.getResources().getConfiguration().orientation==1) { //portrait 

      NewsList_fragment newsFrag = new NewsList_fragment(); //init any fragments that may be used 

      FragmentManager fManager = getFragmentManager(); //prepare fragment manager 
      FragmentTransaction fTransaction = fManager.beginTransaction(); 

      // Add fragments using fTransaction and then commit 
      fTransaction.add(R.id.news_list_container, newsFrag); 
      fTransaction.commit(); 
      } 

     else if (this.getResources().getConfiguration().orientation==2) { //landscape 

      NewsList_fragment newsFrag = new NewsList_fragment(); //init any fragments that may be used 
      Details_fragment detailsFrag = new Details_fragment(); 


      FragmentManager fManager = getFragmentManager(); //prepare fragment manager 
      FragmentTransaction fTransaction = fManager.beginTransaction(); 

      // Add fragments using fTransaction and then commit 
      fTransaction.add(R.id.news_list_container, newsFrag); 
      fTransaction.add(R.id.details_container, detailsFrag); 

      fTransaction.commit(); 
      } 

가 사전에 감사

+0

으로 내 문제를 해결했습니다. details_view.setVisibility (View.GONE); 관심사를 보여준 사람 덕분에 –

답변

0

에서 귀하의 경우, 당신은 라의 가시성을 설정해야합니다 세부 정보 조각이 View.GONE에 포함됩니다. View.GONE은 레이아웃이 보이지 않으며 공간을 차지하지 않는다는 것을 의미합니다. View.INVISIBLE은 뷰가 보이지 않지만 공간이 여전히 남아 있음을 의미합니다.

LinearLayout detailsContainer = (LinearLayout) findViewById(R.id.details_container); 
int orientation = getResources().getConfiguration.orientation; 
if (orientation == 1) // means orientations is portrait 
    detailsContainer.setVisibility(View.GONE); 
+0

트릭을 수행합니다. 엄청 고마워 :) –

관련 문제