2017-08-30 194 views
-1

我有什麼:空間Recyclerview項目平均(水平)

enter image description here

我想要什麼:

enter image description here

片段佈局:

<RelativeLayout xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/fragment_profile_selection_dim_bg" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#80000000"> 

<android.support.constraint.ConstraintLayout 
    android:id="@+id/" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="320dp" 
    android:layout_height="match_parent" 
    android:layout_centerInParent="true" 
    android:clipChildren="false"> 

    <LinearLayout 
     android:id="@+id/linearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="80dp" 
     android:elevation="1dp" 
     android:orientation="horizontal"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:paddingBottom="16dp" 
      android:text=".." 
      android:textColor=".." 
      android:textSize="17.3sp" /> 
    </LinearLayout> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerview" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="24dp" 
     android:layout_marginStart="24dp" 
     android:layout_marginTop="20dp" 
     android:descendantFocusability="afterDescendants" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/linearLayout" 
     > 

    </android.support.v7.widget.RecyclerView> 

</android.support.constraint.ConstraintLayout> 
</RelativeLayout> 

Recyclerview片段:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:gravity="center_vertical" 
    android:layout_marginTop="15dp" 
    android:focusable="true" 
    android:focusableInTouchMode="true"> 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="10dp"/> 

    <TextView 
     android:id="@+id/" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="11.6sp"/> 
</LinearLayout> 

我正在使用recyclerviews GridManagerLayout(3列)。如果可能的話,我想使用xml屬性來做到這一點,但當然我會接受其他想法。當然,一些解釋也會很好 - 我想了解我的問題,不僅解決問題。 :)

回答

1

你必須設置你的TextView的寬度相同的ImageView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:gravity="center_vertical" 
android:layout_marginTop="15dp" 
android:focusable="true" 
android:focusableInTouchMode="true"> 

<ImageView 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_marginBottom="10dp"/> 

<TextView 
    android:id="@+id/" 
    android:layout_width="50dp" 
    android:layout_height="wrap_content" 
    android:maxLines="1" 
    android:textSize="11.6sp"/> 

0

你有recyclerView行改變TextView寬度(wrap_content50dp)。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="50dp" 
     android:layout_height="50dp" 
    android:orientation="vertical" 
    android:gravity="center_vertical" 
    android:layout_marginTop="15dp" 
    android:focusable="true" 
    android:focusableInTouchMode="true"> 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="10dp"/> 

    <TextView 
     android:id="@+id/" 
     android:layout_width="50dp" 
     android:layout_height="wrap_content" 
     android:maxLines="1" 
     android:ellipsize="end" 
     android:textSize="11.6sp"/> 
</LinearLayout> 
+0

正因爲如此 - 文本與ImageView的完全對齊,但仍recyclerview最後一個元素本身和佈局邊緣 – JoshuaMad

+0

只有最後一個項目的問題之間更大的空間現在我更新了我的代碼檢查@JoshuaMad –

+0

每一行的最後一個元素.. :(就像行中的元素不會填滿所有的橫向空間 – JoshuaMad

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="50dp" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:gravity="center_vertical" 
    android:layout_marginTop="15dp" 
    android:focusable="true" 
    android:focusableInTouchMode="true"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginBottom="10dp"/> 

    <TextView 
     android:id="@+id/" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
    `/> 
</LinearLayout> 

Change your parent layout width as a 50dp 
Hope this will help you