2010-11-18 25 views

Trả lời

9

lẽ bạn có thể có một trong mỗi và chuyển tầm nhìn của họ. Khi nút được nhấp, lấy văn bản của một cái nhìn thấy được, áp dụng nó cho người vô hình, và sau đó trao đổi tầm nhìn của họ.

+3

@MarvinLabs: +1, ông đã nhanh hơn;) –

4

Bạn có thể có cả bố cục và mọi lúc chỉ có một trong số chúng được hiển thị. Khi giá trị EditText thay đổi, hãy cập nhật TextView ẩn để đồng bộ hóa chúng.

+2

@ Rich: Ok, bạn nhanh hơn :-) –

0

Tôi chưa bao giờ thử nó nhưng bạn có thể (có thể) sử dụng EditText và đặt nền cho TextView. Sau đó, onfocus thay đổi bạn chỉ có thể hoán đổi hình nền dựa trên những gì bạn muốn xem tại bất kỳ thời điểm nào. Tôi sẽ cố gắng thực hiện nó và xem nếu nó sẽ làm việc

67

tốt nhất để sử dụng một ViewSwitcher

... 
    <ViewSwitcher 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/my_switcher" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <TextView 
      android:id="@+id/clickable_text_view" 
      android:clickable="true" 
      android:onClick="TextViewClicked" 
      android:text="@string/some_value" /> 

     <EditText 
      android:id="@+id/hidden_edit_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/some_value" /> 
    </ViewSwitcher> 
... 

Sau đó, bạn có thể chuyển đổi các quan điểm của

public void TextViewClicked() { 
    ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.my_switcher); 
    switcher.showNext(); //or switcher.showPrevious(); 
    TextView myTV = (TextView) switcher.findViewById(R.id.clickable_text_view); 
    myTV.setText("value"); 
} 
+0

Tôi thật sự nghĩ ra khỏi tất cả chúng, câu trả lời này là tốt nhất. Nó đơn giản hơn rất nhiều. Tôi tò mò. Khi nào điều này nên được sử dụng? Tôi đọc tài liệu, và nó nói về công cụ kiểu hoạt hình. Nhưng trong trường hợp này, nó có ý nghĩa để sử dụng nó. Vì vậy, có một lý do để không sử dụng nó trong trường hợp này? – Andy

+0

Xem trình chuyển đổi hoạt động độc đáo và bạn có tùy chọn thêm hoạt ảnh dễ dàng. – Patrick

+1

Tốt, nhưng thêm không gian trong khai báo 'switcher' –

0

Những gì tôi nghĩ tốt nhất là thực sự sử dụng khái niệm Framelayout.

như vậy mà bố trí ban đầu trông giống như

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
. 
. 
. 
</Linearlayout> 

Nơi nó bên Framelayout như thế này.

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
. 
. 
. 
</Linearlayout> 

<!-- The Magic is here --> 
<View 

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



</FrameLayout> 

Tại đây LinearLayout sẽ giữ tất cả Chế độ xem EditText của bạn. Cũng nhớ tạo nền của EditText View null.

Như thế này

<EditText 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:id="@+id/editInp" 
     android:hint="@string/hello_world" 
     android:background="@null" 
     android:singleLine="true" 
     android:inputType="textCapWords"/> 

hoặc

<EditText 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:id="@+id/editInp" 
     android:hint="@string/hello_world" 
     android:background="@android:drawable/transparent" 
     android:singleLine="true" 
     android:inputType="textCapWords"/> 
Các vấn đề liên quan