2016-01-23 175 views
2

我的應用程序隱藏/顯示視圖問題由屏幕的與佈置在2×2其中每個表4佈局圖,示出視頻與機器人

enter image description here

每個視圖包括播放控制。當我按下一個按鈕使全屏顯示時,應用程序顯示如下。 查看2重疊到全屏查看3。我想只能說明VIEW3爲全屏,並避免視圖2

enter image description here

下面的代碼是用於隱藏/顯示視圖

@Override 
public void toggleFullScreen() 
{ 
    mbFullscreen = !mbFullscreen; 
    mStrTmp = ""; 
    Trace((ViewGroup)getRootView(), mbFullscreen); 
    mMessage.setText(mStrTmp); 
} 

private void Trace(ViewGroup layout, boolean bFullScreen) { 
    View FullScreenChild = null; 
    ViewGroup FullScreenLayout = null; 
    for(int i = 0; i < layout.getChildCount(); i++){ 
     View child = layout.getChildAt(i); 
     if(child instanceof MtxVideoView){ 
      if(child == this){ 
       FullScreenChild = child; 
       FullScreenLayout = layout; 
      } 
      layout.setVisibility(bFullScreen?View.GONE:View.VISIBLE); 
      child.setVisibility(bFullScreen?View.GONE:View.VISIBLE); 
     } 
     else if (child instanceof ViewGroup) { 
      Trace((ViewGroup) child, bFullScreen); 
     } 
    } 

    if(bFullScreen){ 
     if(FullScreenLayout != null) 
      FullScreenLayout.setVisibility(View.VISIBLE); 

     if(FullScreenChild != null){ 
      FullScreenChild.setVisibility(View.VISIBLE); 
      mStrTmp = mStrTmp + "FullScreen"; 
     } 
    } 
} 

下面

enter image description here

回答

1

預期顯示輸出我對你amuch簡單的解決方案。使用FrameLayout來顯示您的選擇佈局。添加的ImageView在上面選擇佈局,但保持它看不見這樣的: -

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.5" > 

      <LinearLayout 
       android:id="@+id/item_1" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="0.5" 
       android:background="#000" 
       android:gravity="center" 
       android:orientation="vertical" > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_launcher" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Item 1" 
        android:textSize="25sp" /> 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/item_2" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="0.5" 
       android:background="#d5d5d5" 
       android:gravity="center" 
       android:orientation="vertical" > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_launcher" /> 

       <TextView 
        android:id="@+id/textView2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Item 2" 
        android:textSize="25sp" /> 
      </LinearLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/item_3" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.5" > 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="0.5" 
       android:background="#d5d5d5" 
       android:gravity="center" 
       android:orientation="vertical" > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_launcher" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Item 3" 
        android:textSize="25sp" /> 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/item_4" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="0.5" 
       android:background="#000" 
       android:gravity="center" 
       android:orientation="vertical" > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_launcher" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Item 4" 
        android:textSize="25sp" /> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/hidden_imageView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="centerCrop" /> 

</FrameLayout> 

結果會是這樣 enter image description here

現就本次網的點擊項目使隱藏ImageView的可見光和改變形象ImageView的相應

findViewById(R.id.item_1).setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      findViewById(R.id.select_image).setVisibility(View.GONE); 
      findViewById(R.id.hidden_imageView).setVisibility(View.VISIBLE); 
      ((ImageView) findViewById(R.id.hidden_imageView)) 
        .setBackgroundResource(R.drawable.walking); 

     } 
    }); 

    findViewById(R.id.item_2).setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      findViewById(R.id.select_image).setVisibility(View.GONE); 
      findViewById(R.id.hidden_imageView).setVisibility(View.VISIBLE); 
      ((ImageView) findViewById(R.id.hidden_imageView)) 
        .setBackgroundResource(R.drawable.ic_launcher); 

     } 
    }); 

...等等

和導航回使用自來水上的ImageView這樣

findViewById(R.id.hidden_imageView).setOnClickListener(
      new OnClickListener() { 

       @Override 
       public void onClick(View v) { 

        findViewById(R.id.select_image).setVisibility(
          View.VISIBLE); 
        findViewById(R.id.hidden_imageView).setVisibility(
          View.GONE); 

       } 
      }); 

enter image description here

看起來不錯,即使你旋轉屏幕

enter image description here

希望它會幫助你。

+0

您的解決方案很好。謝謝 – Riskhan