2016-01-23 123 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