2014-02-13 25 views
0

我創建了一個ListView,它顯示了播放它們的可能性的不同媒體文件。 imageAndroid TextView中的長文本推出其他對象

每行由一個帶有兩個小部件的RelativeLayout組成。 (SeekBar和其他) image

這個RelativeLayout的上半部分也是一個RelativeLayout。 它由三個部分組成:

  • 播放按鈕(用於填充一個的LinearLayout內)
  • 一個TextView的文件名
  • 一個LinearLayout中框一些標籤 image

他們使用android:layout_toRightOf屬性放在一起。

這很有效,除非文件名太長。 image

長文件名會導致正確的LinearLayout'Box'被推到屏幕之外。

此外,整個(內部)RelativeLayout會無緣無故地垂直拉伸。

我已經嘗試設置android:ellipsize="end"android:singleLine="true"。但是這並沒有解決它。

繼承人的全碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" 
android:padding="8dp" > 

<!-- Top Box --> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/fragment_play_row_topbox" > 

    <!-- Play button --> 
    <LinearLayout android:id="@+id/fragment_play_row_iconBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:padding="4dip" > 

     <ImageButton 
      android:id="@+id/fragment_play_row_icon" 
      android:layout_width="48dp" 
      android:layout_height="48dp" 
      android:src="@android:drawable/ic_media_play" /> 

    </LinearLayout> 

    <!-- Big Text --> 
    <TextView 
     android:id="@+id/fragment_play_row_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_toRightOf="@+id/fragment_play_row_iconBox" 
     android:text="\??" 
     android:textSize="24dp" 
     android:ellipsize="end" 
     android:singleLine="true" /> 

    <!-- Size & Duration & Button--> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_centerVertical="true" 
     android:layout_toRightOf="@+id/fragment_play_row_text" 
     android:layout_alignParentRight="true" 
     android:gravity="right" > 

     <TextView 
      android:id="@+id/fragment_play_row_size" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text=" ?? MB" /> 

     <TextView 
      android:id="@+id/fragment_play_row_duration" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text=" ??:??" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:src="@android:drawable/arrow_down_float" /> 

    </LinearLayout> 
</RelativeLayout> 

<!-- Seek Bar --> 
<SeekBar 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/fragment_play_row_topbox" /> 

</RelativeLayout> 

我希望有人能幫助我解決這個問題。

由於提前,

烏列爾

回答

2

你必須參考的信息佈局爲您的項目的根,它引用父和文本引用的信息的佈局,通過這種方式,您將不會有這個問題,我已經修改了一點點你的佈局只是添加一個id到信息佈局(linearInfo),當你設置一個id時,remmember是「@ + id/my_item」,但是當你引用它時是「 @ id/my_item「,這裏是你的佈局修改,希望它可以幫助你:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" 
android:padding="8dp" > 

<!-- Top Box --> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/fragment_play_row_topbox" > 

    <!-- Play button --> 

    <LinearLayout 
     android:id="@+id/fragment_play_row_iconBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/linearInfo" 
     android:layout_alignTop="@+id/linearInfo" 
     android:padding="4dip" > 

     <ImageButton 
      android:id="@+id/fragment_play_row_icon" 
      android:layout_width="48dp" 
      android:layout_height="48dp" 
      android:layout_gravity="center_vertical" 
      android:src="@android:drawable/ic_media_play" /> 

    </LinearLayout> 

    <!-- Big Text --> 

    <TextView 
     android:id="@+id/fragment_play_row_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/linearInfo" 
     android:layout_alignTop="@+id/linearInfo" 
     android:layout_centerVertical="false" 
     android:layout_toLeftOf="@+id/linearInfo" 
     android:layout_toRightOf="@+id/fragment_play_row_iconBox" 
     android:ellipsize="end" 
     android:gravity="center_vertical" 
     android:singleLine="true" 
     android:text="\?? Ultra Hyper Mega Giant Text" 
     android:textSize="24dp" /> 

    <!-- Size & Duration & Button--> 

    <LinearLayout 
     android:id="@+id/linearInfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_centerVertical="true" 
     android:gravity="right" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/fragment_play_row_size" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text=" ?? MB" /> 

     <TextView 
      android:id="@+id/fragment_play_row_duration" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text=" ??:??" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:src="@android:drawable/arrow_down_float" /> 

    </LinearLayout> 
</RelativeLayout> 

<!-- Seek Bar --> 
<SeekBar 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/fragment_play_row_topbox" /> 

</RelativeLayout> 
+0

做了這個回答r有效? – r1ckr

+0

是的,它的確如此。但是你能解釋一下爲什麼嗎?我是否總是必須開始將最右邊的對象與父對齊,然後將所有其他對象與該對象對齊? 這裏的規則是什麼? 另外:如果我按照你寫的那樣進行對齊,然後再添加到播放圖標的LinearLayout:android:layout_toLeftOf =「@ + id/fragment_play_row_text」,應用程序崩潰。 這是因爲android無法決定在哪裏放置什麼,因爲多餘的對齊選項? (播放圖標應該留在文本視圖的左側,文本視圖應該在播放圖標的右側 - 這是可能的,但是是多餘的) – Ansgar

+0

如果我使用的是LinearLayout,我該怎麼做?(LinearLayout中的三個水平對象,中間的Object推出正確的) 因爲我不能在LinearLayout中使用'android:layout_toLeftOf' ... – Ansgar

相關問題