簡體   English   中英

Android RecyclerView弄亂了layout_weight

[英]Android RecyclerView messing up layout_weight

我在DialogFragment有一個非常簡單的RecyclerView 。單行項目應該顯示圖像,名字和姓氏以及一些數字。 它們在layout_weight的幫助下進行布局,以平均共享可用空間。

由於某些原因,某些項目似乎隨機地計算出layout_weight錯誤。

請注意,在編輯器中預覽和滾動有問題的項目拿出來看 ,這個問題是固定的,布局恢復正常。

正如您在圖像中看到的那樣,在第一項(並不總是(只是)第一項)中,圖像空間太大。

問題

我的布局如下;

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/dodger_blue"
    android:orientation="horizontal"
    android:padding="8dp">

    <ImageView
        android:id="@+id/iv_face"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:orientation="vertical">

        <TextView
            android:id="@+id/et_first_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLargeInverse"
            android:textStyle="bold"/>

        <TextView
            android:id="@+id/et_surname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMediumInverse"/>

    </LinearLayout>

    <TextView
        android:id="@+id/et_id"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceMediumInverse"/>

    <TextView
        android:id="@+id/et_place"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.8"
        android:gravity="center|end"
        android:textAppearance="?android:attr/textAppearanceLargeInverse"/>
</LinearLayout>

還有我的適配器; https://gist.github.com/StefanDeBruijn/f032eac6619ac1b8420e352b883ea4dd

我懷疑這是由於在圖像視圖中設置了大圖像而發生的。 由於您已將圖像的高度設置為match_parent。 為了保持長寬比,它還在整個寬度上擴展。

可能您應該嘗試將此屬性添加到xml文件中,並固定圖像的高度。

android:scaleType =“ fitXY” android:layout_height = 100dp

讓我知道這是否可以解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM