2016-02-27 56 views
0

上午在Android应用程序中工作,其中有两个活动是主要活动和模式活动。我的第一个活动是主要活动有一些隐形图标,enter image description here 第二个活动是模式活动。当我点击按钮时,我的第二个活动enter image description here我回顾了我的第一个活动,我希望看不见的图标应该可见。 enter image description here如何在android中的可见布局

enter code here 

    pro.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      autobtn.setImageResource(R.drawable.auyto); 
      pro.setImageResource(R.drawable.proactiv); 
      Intent it = new Intent(ModeActivity.this, Mainactivity.class); 
      startActivity(it); 
     } 
    }); 

回答

1

您可以使用

yourView.setVisibility(View.GONE); 

您可以通过使用findViewByID :) 得到引用您的视图中隐藏视图,当你想要把它找回来只是说yourView.setVisibility(View.VISIBLE);

由于根据你的问题,在你的模式活动的onCreate或onStart你可以隐藏你的隐形图标,如

@Override 
    protected void onStart(){ 
     super.onStart(); 
     yourView.setVisibility(View.GONE); 
    } 

并且在模式活动按钮的onClickListener中,您可以使该按钮可见。在onclickListener您的按钮,把你想要的图标显示和隐藏对相同的按钮(按钮使用像切换)备用水龙头代码

yourView.setVisibility(View.VISIBLE); 

那所有。如果然后把下面的代码

if (yourView.getVisibility() == View.VISIBLE) { 
     yourView.setVisibility(View.GONE); 
    } else { 
     // Either gone or invisible 
     yourView.setVisibility(View.VISIBLE); 
    } 

希望它能帮助:)

+0

我在哪里可以在主要活动中使用这些代码是它的onResume( ) –

+0

你可以把它放在onStart中,就像我已经显示的那样,或者在你想要的任何地方创建onCreate :)只要确保在调用yourView.setVisibility(View.VISIBLE)之前获得对图标的引用;你的视图是你的图标:) –

+0

每当你的主要活动被加载onStart()和onCreate在你的情况下被调用:)所以它可以把它放在这个方法中的任何一个:)任何具体的为什么你想把它放在onResume ??它应该在那里也很好:) –

0

为了让您图标可见,你可以使用

icon.setVisibility(View.VISIBLE); 
0

我认为你正在使用SurfaceView,如果是,那么让你的SurfaceView中的FrameLayout,并通过SurfaceView地方的另一个View

喜欢这个

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <SurfaceView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:gravity="bottom" 
     android:orientation="horizontal" 
     > 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_logo"/> 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_logo"/> 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_logo"/> 


    </LinearLayout> 


</FrameLayout> 
+0

我该如何解决它 –

+0

只是重叠你的SurfaceView与另一个查看 – Kushal

+0

其确定请请看看我的照片,我张贴在第一图片有隐藏按钮,当我点击亲在我的第二张图片我回来了第一个活动,我想这些按钮,我在红色方块显示它 –