2017-08-30 129 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