2011-12-23 38 views
12

Tôi gặp sự cố lạ với TextView, nó cắt bớt một phần văn bản ở cuối. Bố cục của tôi trông giống nhưTextView cắt văn bản khi đủ dài

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="top|center_horizontal" 
     android:gravity="top|center_horizontal" 
     android:orientation="vertical" > 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="top|center_horizontal" 
      android:gravity="top|center_horizontal" 
      android:orientation="horizontal" 
      android:layout_weight="1" 
      android:layout_marginBottom="5dp"> 
      <Button 
       android:id="@+id/btnPreviousQuestion" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/selector_arrow_left" 
       android:clickable="true" 
       android:visibility="gone" > 
      </Button> 
      <TextView 
       android:id="@+id/txtQuestion" 
       style="@style/question_text" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:gravity="top|center_horizontal" 
       android:layout_weight="1" 
       /> 
      <Button 
       android:id="@+id/btnNextQuestion" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="10dp" 
       android:background="@drawable/selector_arrow_right" 
       android:clickable="true" > 
      </Button> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_weight="1" 
      android:orientation="horizontal" > 
      <WebView 
       android:id="@+id/wvMultimediaQuestion" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom|center_horizontal" 
       android:layout_marginLeft="50dp" 
       android:layout_marginRight="55dp" 
       android:layout_weight="1" 
       android:visibility="gone" /> 
     </LinearLayout> 
    </LinearLayout> 

và txtCách tắt văn bản khi đủ dài. Điều gì là sai, không ai biết?

+1

cắt - khi bạn hiển thị văn bản hoặc khi bạn phân tích cú pháp từ TextView? – hovanessyan

+0

@Damir bạn có thể đăng ảnh chụp màn hình của văn bản bị cắt. nhầm lẫn nhỏ trong câu hỏi. Tôi đã thử nghiệm bố cục của bạn, hiển thị toàn bộ văn bản của nó. –

Trả lời

5

Có một số thuộc tính bạn cần đặt, nhưng trước tiên hãy cho chúng tôi biết bạn muốn chính xác loại văn bản nào, một dòng hoặc nhiều dòng?

Có một số thuộc tính mà bạn có thể chăm sóc:

android:singleLine="true" // or false 
android:ellipsize="marquee" // must check 
android:lines="1" 
49

Make sử dụng các thuộc tính

android:lines="1" 
    android:scrollHorizontally="true" 
    android:ellipsize="end" 

sẽ nối "..." ở cuối. Nhưng điều này sẽ không giải quyết vấn đề trong tab tổ ong

Vì vậy, cho máy tính bảng tổ ong thêm atttibute sau đây cũng

android:singleLine="true" 

Mặt khác nếu bạn đòi hỏi hiệu ứng marquee

android:singleLine="true" 
android:ellipsize="marquee" 
android:marqueeRepeatLimit="marquee_forever" 
android:scrollHorizontally="true" 
android:focusable="true" 
android:focusableInTouchMode="true 
+0

Mã của bạn trên hiệu ứng vùng chọn chỉ hoạt động đối với một TextView duy nhất trong bố cục. Nếu bạn cố gắng di chuyển nhiều mục thì nó không hoạt động. Làm thế nào để bạn đi về nhiều TextView để có hiệu ứng này? – Brandon

0

Bạn cần phải thiết lập android: minLines = "2"

0

Nếu bạn mong đợi độ dài văn bản khác nhau cho chế độ xem của mình hoặc bạn sẽ thay đổi textSize của các trường hợp khác nhau của TextView của bạn sau đó bạn nên sử dụng View.addOnLayoutChangeListener().

Xem ví dụ tại đây: https://stackoverflow.com/a/44069734/1402087

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