2012-03-04 28 views
10

Tôi có một glsurface chiếm toàn màn hình. Tại một nút bấm, tôi muốn bố cục khác xuất hiện (loại cài đặt của sự vật). Nếu tôi bắt đầu với lớp phủ có thể nhìn thấy, tôi có thể làm cho nó vô hình và sau đó có thể nhìn thấy một lần nữa mà không có vấn đề gì. Nhưng nếu tôi bắt đầu với nó vô hình, tôi không thể làm cho nó bao giờ có thể nhìn thấy một lần nữa. Mã sau:android setVisibility không hiển thị nếu ban đầu được đặt thành invisble

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

    <android.opengl.GLSurfaceView 
    android:id="@+id/glPlaySurface" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
</android.opengl.GLSurfaceView> 

<RadioGroup 
    android:id="@+id/radioGroup1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:orientation="horizontal" > 

    <RadioButton 
     android:id="@+id/btnRotate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:checked="true" 
     android:text="R" 
     android:textColor="#000" /> 

    <RadioButton 
     android:id="@+id/btnPan" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="15dp" 
     android:text="P" 
     android:textColor="#000" /> 
</RadioGroup> 

<Button 
    android:id="@+id/btnLights" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_marginLeft="15dp" 
    android:layout_toRightOf="@+id/radioGroup1" 
    android:text="Lights" /> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layoutLights" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:visibility="visible" <--- Does not work if set to invisible 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 

    android:background="#fff" > 

    <Button 
    android:id="@+id/btnLightsOK" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginLeft="15dp" 
    android:text="OK" /> 

    <Button 
    android:id="@+id/btnLights" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginLeft="15dp" 
    android:text="OK" /> 

</RelativeLayout> 

</RelativeLayout> 


private OnClickListener mOnLightsClick = new OnClickListener() { 
    public void onClick(View arg0) { 
     if(mLayoutLights.getVisibility() == View.VISIBLE) { 
      mLayoutLights.setVisibility(View.INVISIBLE); 
     } 
     else { 
      mLayoutLights.setVisibility(View.VISIBLE); 
     } 
    } 
}; 
+0

sự cố liên quan đến glsurface. Nếu tôi thay thế các glsurface với một surfaceview bình thường nó hoạt động tốt. – user1248322

+0

thông tin thêm: nếu tôi đặt glsurface thành GONE, đặt bố cục thành VISIBLE, sau đó đặt glsurface trở lại thành VISIBLE - nó hoạt động. Nhưng ... nếu tôi đặt glsurface thành INVISIBLE thay vì GONE - nó không hoạt động. – user1248322

+0

ok - surface_view_overlay trong bản demo api thực hiện chính xác những gì tôi đang tìm kiếm - tôi sẽ thấy nơi tôi đã đi sai và sau đó đăng bài. – user1248322

Trả lời

10

Got nó. Bạn phải đặt chế độ hiển thị của tất cả các mục trong bố cục, không chỉ bố cục. Vì vậy, mã này đã làm việc:

if (mLayoutLights.getVisibility() == View.VISIBLE) { 
    ((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.GONE); 
((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.GONE); 
mLayoutLights.setVisibility(View.GONE); 
} else { 
    mLayoutLights.setVisibility(View.VISIBLE); 
((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.VISIBLE); 
((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.VISIBLE); 
} 
+1

Cảm ơn người đàn ông, tôi đã có cùng một vấn đề. – Enrichman

1

Tôi khuyên bạn nên thử ba điều độc lập.

  1. Thay đổi chiều rộng và chiều cao bố cục để bọc nội dung vì nó có thể là vấn đề phù hợp với cha mẹ.
  2. Calling bringToFront trên quan điểm
  3. Bao bì các surfaceView trong một FrameLayout (điều này có liên quan đến # 2, nhưng nó vẫn có thể giúp đỡ)
+0

Cảm ơn - nhưng không ai trong số đó tạo sự khác biệt. – user1248322

+0

Bạn có biết nếu chuỗi hiển thị đang chạy hoặc thậm chí bắt đầu trên bề mặt không? – BeatingToADifferentRobot

+0

có - 3d phản hồi để chạm và hiển thị đúng (tôi đã thử cả hiển thị liên tục và hiển thị khi không có sự khác biệt) – user1248322

-3
case R.id.title_call_button: 
if(llButtonCallNow.getVisibility() != View.VISIBLE){ 
llButtonCallNow.setVisibility(View.VISIBLE); 
} 
    else{ 
    llButtonCallNow.setVisibility(View.GONE); 
    Toast.makeText(getBaseContext(), ("Im here baby :)"), 
    Toast.LENGTH_SHORT).show(); 

    } 
break; 
14

Đã lỗi tương tự nhưng đó là do sai lầm ngớ ngẩn của tôi không sử dụng UiThread.

Activity act = (Activity)context; 
act.runOnUiThread(new Runnable(){ 
@Override 
public void run() { 
    mLayoutLights.setVisibility(View.VISIBLE); 
} }); 
+1

Cảm ơn người đàn ông, nó đã giải quyết được vấn đề của tôi! Tôi đã thiết lập khả năng hiển thị trong một cuộc gọi lại và không biết tại sao chế độ xem không được cập nhật ngay lập tức, nhưng bây giờ nó hoạt động. Dường như tôi cần làm việc với các chủ đề giao diện người dùng. – Jack

2

Trong trường hợp của tôi, với SurfaceView đơn giản, tôi chỉ đặt Chế độ xem thành GONE trong xml, không thể LỰA CHỌN. Sau đó, tôi có thể thiết lập VISIBILITY một cách chính xác sau đó.

+0

Việc này đã giải quyết được vấn đề của tôi! Cảm ơn! :) – acegs

-2

Chỉ cần đặt chiều rộng và chiều cao của thuộc tính thành "fill_parent" thay vì "match_parent". Không cần phải thiết lập khả năng hiển thị cho tất cả các trẻ em, nhưng chỉ để các container cấp cao hơn/yếu tố.

Các vấn đề liên quan