2012-07-16 14 views
5

मैं निम्नलिखित लेआउट कैसे प्राप्त कर सकता हूं, टेक्स्टव्यू TextView के साथ ellipsize अंत के साथ और wrap_content और तुरंत टेक्स्ट व्यू के दाईं ओर देखें?एंड्रॉइड - दाएं संरेखित दृश्य के साथ इलिप्सिज़

|[TextView] [View]    | 

|[TextView TextView] [View]  | 

|[TextView TextView T...] [View]| 

[संपादित करें]

निम्नलिखित TableLayout सही व्यवहार देता है::

<TableLayout 
    android:id="@+id/upper_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_toLeftOf="@+id/alert_button" 
    android:shrinkColumns="0" 
    android:stretchColumns="2" > 

    <TableRow> 

     <TextView 
      android:id="@+id/name_textview" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:ellipsize="end" 
      android:includeFontPadding="false" 
      android:lines="1" 
      android:paddingTop="2dp" 
      android:scrollHorizontally="true" /> 

     <TextView 
      android:id="@+id/unread_count_textview" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:gravity="center" 
      android:includeFontPadding="false" 
      android:paddingBottom="0dp" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp" 
      android:paddingTop="2dp" /> 
    </TableRow> 
</TableLayout> 

यहाँ कैसे लेआउट व्यवहार करना चाहिए के तीन उदाहरण, अलग TextView चौड़ाई के साथ कर रहे हैं TableLayout 3 कॉलम का उपयोग करता है, आखिरी हैक है: strechColumns संपत्ति यह सभी उपलब्ध स्थान लेती है, इसलिए दूसरा TextView हमेशा पहले के दाईं ओर है। shrinkColumns संपत्ति के कारण पहले TextView सही ढंग से इलिप्सिज़ करें।

हालांकि, मुझे यह प्राप्त करने के लिए TableLayout का उपयोग करने का विचार पसंद नहीं है। क्या कोई बेहतर तरीका जानता है?

धन्यवाद

+0

क्या यह एक सूची है या नहीं? – Yury

+0

हां, यह एक पंक्ति लेआउट है। – gdelente

उत्तर

0

इस (मैं अब यह जांच नहीं कर सकता है, लेकिन देखने की मेरी बात करने के लिए इसे काम करना चाहिए) का प्रयास करें:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="6dip" > 

    <TextView 
     android:id="@+id/my_txtvw_txtvw" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:ellipsize="marquee" 
     android:maxLines="1" /> 

    <TextView 
     android:id="@+id/my_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/my_txtvw_txtvw" 
     android:maxLines="1" /> 

</RelativeLayout> 
+0

धन्यवाद लेकिन दुर्भाग्यवश इस समाधान के साथ बाएं टेक्स्ट व्यू बहुत लंबा है जब सही टेक्स्ट व्यू स्क्रीन से धक्का दिया जाता है। – gdelente

0

इस प्रयास करें:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/my_view" 
     android:ellipsize="end" 
     android:maxLines="1" 
     android:layout_alignParentLeft="true" 
     android:text="blablabla blablabla" 
     android:layout_centerVertical="true" 
     android:gravity="center_vertical|left" /> 

    <TextView 
     android:id="@+id/my_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:maxLines="1" /> 

</RelativeLayout> 

मैं नहीं कर रहा हूँ सुनिश्चित करें कि आप android:ellipsize="end" या android:ellipsize="marquee" चाहते हैं। मुझे लगता है कि लेआउट आपके लिए ठीक काम करेगा, बस इलिप्सिज़ वैल्यू आईडी को प्रतिस्थापित करें।

मुझे अपनी प्रगति के बारे में बताएं ...

+0

आपके उत्तर के लिए धन्यवाद yugidroid। आपने दूसरे दृश्य पर 'alignParentRight =" true "रखा है। समस्या यह है कि दृश्य हमेशा दूर दाईं ओर गठबंधन किया जाएगा। मैं "my_view" को "text1" के दाईं ओर होना चाहता हूं। एक बार जब पहला टेक्स्ट व्यू ("टेक्स्ट 1") माता-पिता के अंदर फिट होने के लिए बहुत लंबा होता है, तो "my_view" को गठबंधन किया जाता है और "text1" को इलिप्सकृत किया जाता है। 'alignParentRight = "true" को हटाने में मदद नहीं मिली क्योंकि "text1" को my_view द्वारा बाईं ओर स्क्रीन से धक्का दिया गया है। – gdelente