2012-06-21 147 views
0

我採取的ListView 2個textviews,以供參考使用Basic Layout and Formatting的TextView重疊2個textviews

而是股票名稱也很短,我使用很長的文字,所以當我用很長的文字,它與第二個重疊。

那麼如何讓它正確,以便2個文本瀏覽不會相互重疊。

+0

[查看此示例](http://samir-mangroliya.blogspot.in/p/android-customized-listview。 html) –

回答

0

您可以使用下面的代碼來解決問題:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:weightSum="1"> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:id="@+id/ticker_symbol" 

     android:text="sdasd sadas" 
     android:layout_weight=".5"/> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:id="@+id/ticker_price" 
     android:text="dfsd" 
     android:layout_weight=".5" 
     android:gravity="right" /> 
</LinearLayout> 

輸出:

Output of Code

+0

我使用相對佈局,而不是線性佈局,所以它不會與該 – user1455192

+0

工作是否有任何具體原因使用線性佈局 –

+1

謝謝,正是我所需要的。 – user1455192

0

爲避免重疊,您可以將第二個textview設置爲與右對齊(android:layout_toRightOf)。

例如:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:id="@+id/ticker_symbol" 
     android:layout_alignParentLeft="true" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:id="@+id/ticker_price" 
     android:layout_toRightOf="@id/ticker_symbol" 
     android:layout_alignParentRight="true" /> 
</RelativeLayout> 
+0

是的,它在示例中這樣做,但它仍然與另一個textview重疊,我的第二個textview根本不轉移,並且第一個textview與它重疊 – user1455192

+0

這行'android:layout_toRightOf =「@ id/ticker_symbol」'是我添加的。這不是原來的例子。您可以添加您正在使用的XML代碼,以便我們可以討論它嗎? –

+0

您也可以使用'android:weight'屬性爲每個textview而不是'wrap_content'設置寬度爲50%。檢查出這個http://stackoverflow.com/questions/4961355/percentage-width-in-a-relativelayout –

0

我猜你的意思是由於長期的長度的文本會轉到下一行或下一個TextView

所以我建議你使用textView屬性android:ellipsized =「end」,也可以使用android:single_line =「true」來代替這個,你可以直接指定maxline = 1 我不確定名字拼寫是否正確檢查打字時

<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:id="@+id/ticker_symbol" 
     android:ellipsezed="end" 
     android:singe_line="true" 
     android:layout_alignParentLeft="true" /> 

希望對您這個解釋炒菜鍋,讓我知道..