2013-04-23 47 views
20

Bốn chế độ xem đang sử dụng cùng một xml. Tôi muốn hiển thị bố cục tuyến tính cho chỉ view 1. Tôi đặt android:visibility="gone" vào xml. Và sau đó tôi làm như sau cho view 1 -bố cục Android có chế độ hiển thị GONE

LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone); 

layone.setVisibility(View.VISIBLE); 

Nhưng điều đó không đặt khả năng hiển thị hiển thị.

Không thể hiển thị chế độ xem sau khi được tuyên bố là GONE trong xml?

Tôi không muốn chuyện logic bởi chỉ cần làm,

layone.setVisibility(View.GONE); 

trong mỗi ba quan điểm trừ điểm 1.

Ý tưởng hay ý kiến?

UPDATE:

xml My -

<TextView 
       android:id="@+id/layone" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Previous Page" 
       android:textColor="#000000" 
       android:textSize="16dp" 
       android:paddingLeft="10dp" 
       android:layout_marginTop="10dp" 
       android:visibility="gone" /> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:orientation="horizontal" 
      android:padding="10dp" 
      android:gravity="center_vertical" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp"   
      android:tag="PrevEntries"  
      android:id="@+id/laytwo" 
      android:layout_marginTop="10dp" 
      android:background="@layout/roundedtext" 
      android:visibility="gone" > 

      <TextView 
       android:id="@+id/laythree" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Previous Page" 
       android:textColor="#000000" 
       android:textSize="18dp" 
       android:gravity="center" 
       android:textStyle="bold" /> 

     </LinearLayout> 
+0

Xem cập nhật của tôi với xml. Tôi không muốn hiển thị toàn bộ cái này theo mặc định. Tôi chỉ muốn nó được thể hiện trong quan điểm của tôi 1. –

Trả lời

7

Done bằng cách để nó như thế:

view = inflater.inflate(R.layout.entry_detail, container, false); 
TextView tp1= (TextView) view.findViewById(R.id.tp1); 
LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone); 
tp1.setVisibility(View.VISIBLE); 
layone.setVisibility(View.VISIBLE); 
+0

Nó sẽ giúp mọi người ra nếu bạn nên chấp nhận câu trả lời này để câu hỏi của bạn sẽ hiển thị như là giải quyết. Chúc mừng! –

20
<TextView 
       android:id="@+id/layone" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Previous Page" 
       android:textColor="#000000" 
       android:textSize="16dp" 
       android:paddingLeft="10dp" 
       android:layout_marginTop="10dp" 
       android:visibility="gone" /> 

layone là một TextView.
Bạn đã sai id của mình.

LinearLayout layone= (LinearLayout) view.findViewById(R.id.laytwo);// change id here 

layone.setVisibility(View.VISIBLE); 

nên thực hiện công việc.

hoặc thay đổi như thế này để hiển thị các TextView:

TextView layone= (TextView) view.findViewById(R.id.layone); 

    layone.setVisibility(View.VISIBLE); 
+0

có ok của nó, tôi muốn toàn bộ không được hiển thị bao gồm cả xem văn bản. –

+0

Vậy tại sao bạn lại đề cập đến TextView với LinearLayout? Không nên làm việc. –

+0

chế độ xem văn bản nằm phía trên bố cục tuyến tính và nó là tiêu đề riêng biệt. –

0
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/activity_register_header" 
    android:minHeight="50dp" 
    android:orientation="vertical" 
    android:visibility="gone" /> 

Hãy thử it..For tôi mã này làm việc ..

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