【问题标题】:Custom gridview text alignment issue自定义gridview文本对齐问题
【发布时间】:2016-01-01 05:09:30
【问题描述】:

我正在尝试在底部创建带有图像和文本的自定义 Gridview,但是当我向下滚动时,由于文本导致对齐不匹配 向下滚动后对齐

向下滚动前对齐

gridview.xml

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.staritsolutions.apptitude.CategoryImageResize_Adapter
        android:id="@+id/picture"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1.0"
        android:scaleType="centerCrop" />

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_weight="150"
        android:textColor="@android:color/black" />

</LinearLayout>

</FrameLayout>

【问题讨论】:

  • 固定图片大小或在LinearLayout中使用weightsum

标签: android android-layout android-fragments android-activity gridview


【解决方案1】:

尝试将TextView 的高度更改为wrap_content

 <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="150"
        android:textColor="@android:color/black" />

【讨论】:

  • 还是同样的问题
【解决方案2】:

试试这个

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

<LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical"
     android:weightSum="3" >

<com.staritsolutions.apptitude.CategoryImageResize_Adapter
    android:id="@+id/picture"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="2"
    android:scaleType="centerCrop" />

<TextView
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:gravity="center"
    android:layout_weight="1"
    android:textColor="@android:color/black" />

 </LinearLayout>

</FrameLayout>

【讨论】:

    【解决方案3】:
    You can try this:
    
    <?xml version="1.0" encoding="utf-8"?>
    
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <com.staritsolutions.apptitude.CategoryImageResize_Adapter
            android:id="@+id/picture"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scaleType="centerCrop" />
    
        <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:gravity="center"
            android:layout_weight=".5"
            android:textColor="@android:color/black" />
    
    </LinearLayout>
    
    </FrameLayout>
    
    For TextView - you can set equal weight is 1 & if your text is not big then set fix weight what you want like .2 or .3
    

    【讨论】:

      猜你喜欢
      • 2014-03-25
      • 2012-05-22
      • 2018-12-25
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多