2014-03-01 38 views
1

我想實現一個簡單的屏幕,在這裏我有書的條目水平滾動視圖。我遇到的問題是,它似乎過早切斷,切斷條目。我已經看過類似這樣的其他問題,以及它們的補丁似乎並沒有解決我的,所以我不知道如何處理這個問題。線性佈局還是水平滾動查看被切斷內容

這裏是什麼切斷的樣子:

enter image description here

這裏是我的代碼:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#D3D3D3" > 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="fill" 
     android:orientation="vertical" > 
     <TextView 
      android:id="@+id/textView11" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="2dp" 
      android:text="@string/af" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 
     <HorizontalScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="#A1A1A1" > 
      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="fill_horizontal|end" 
       android:orientation="horizontal" > 
       <RelativeLayout 
        android:id="@+id/relative1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" > 
        <ImageView 
         android:id="@+id/imageView1" 
         android:layout_width="168dp" 
         android:layout_height="258dp" 
         android:layout_marginLeft="5dp" 
         android:layout_marginRight="5dp" 
         android:layout_marginTop="5dp" 
         android:contentDescription="@string/cd" 
         android:src="@drawable/af1" /> 
        <TextView 
         android:id="@+id/textLabel1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_below="@id/imageView1" 
         android:layout_centerInParent="true" 
         android:singleLine="true" 
         android:text="Guilty Wives" /> 
       </RelativeLayout> 
       /*RelativeLayout repeats with different data, cut for brevity*/ 
      </LinearLayout> 
     </HorizontalScrollView> 
    </LinearLayout> 
</ScrollView> 

回答

0

這是一個從未解決的已知問題:(https://code.google.com/p/android/issues/detail?id=20088), 但是這裏是我工作的代碼。 關鍵是要設置水平滾動視圖的寬度來包裝內容和線性(或相對)佈局在其下方,以匹配父的寬度。

<HorizontalScrollView 
    android:id="@+id/group_scroller" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" > 

    <LinearLayout android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
    <RadioGroup 
     android:id="@+id/choices_group" 
     android:layout_width="wrap_content" 
     android:orientation="horizontal" 

     android:paddingTop="4dp" 
     android:paddingBottom="4dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:gravity="center_horizontal" /> 
    </LinearLayout> 
</HorizontalScrollView> 

0

我設法通過增加android:paddingRight="150dip"到的LinearLayout來修復它。

話雖這麼說,我猜這個修復程序是哈克,並沒有真正解決的首要問題。

+1

我還搜查多個問題,在這裏對於這個問題,尋找解決方案是多麼容易:http://stackoverflow.com/a/12181589/2311557 :) – codepleb

0

我嘗試了所有的解決方案,我可以在網絡上找到,但他們都不工作了Horizo​​ntalScrollView內的相對佈局,所以我所做的是隻是一種解決方法。在佈局中添加了所有視圖之後,我在佈局中添加了一個不可見的「行」作爲最後一個子元素,並將其放置在最後一個實際視圖的右側。這有點冒險,但它是最簡單而有效的方式,不需要實現不必要的自定義視圖。

View shim = new View(sender.getApplicationContext()); 
    RelativeLayout.LayoutParams shimParams = new RelativeLayout.LayoutParams(0,ViewGroup.LayoutParams.MATCH_PARENT); 
    shimParams.addRule(RelativeLayout.RIGHT_OF,yourViewIDHere); 
    shim.setLayoutParams(shimParams); 
    YourLayout.addView(shim); 

工程就像一個魅力,並希望這有助於如果有人在尋找有用的東西時絆倒它。