自定义gridview文本对齐问题

时间:2016-01-01 05:09:30

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

我正在尝试使用底部的图像和文本创建自定义网格视图,但是当我向下滚动时,由于文本,对齐方式会不匹配 向下滚动后对齐

enter image description here

向下滚动之前的对齐

enter image description here

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>

3 个答案:

答案 0 :(得分:0)

尝试将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" />

答案 1 :(得分:0)

  

试试这个

<?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>

答案 2 :(得分:0)

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