在GridView中居中子项

阿加瓦尔保险柜

我试图用图像缩略图填充gridview。我无法将子项居中,并且当图像方向不同(即横向与纵向)时会发生不匹配。图片显示了它是如何发出的。我不想更改缩略图的大小,但要在同一级别上显示文本视图,并相应地将imageview居中。

带有未居中子项的照片gridview

Gridview XML:

<syook.syookfirst.classes.Utils.ExpandableHeightGridView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listview_call_photos"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="2dp"
        android:layout_weight="1"
        android:nestedScrollingEnabled="true"
        android:gravity="center"
        android:layout_gravity="center"
        android:numColumns="auto_fit">

    </syook.syookfirst.classes.Utils.ExpandableHeightGridView>

ExpandableHeightGridView类:

public class ExpandableHeightGridView extends GridView
{

boolean expanded = false;

public ExpandableHeightGridView(Context context)
{
    super(context);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs)
{
    super(context, attrs);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);
}

public boolean isExpanded()
{
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    // HACK! TAKE THAT ANDROID!
    if (isExpanded())
    {
        // Calculate entire height by providing a very large height hint.
        // But do not use the highest 2 bits of this integer; those are
        // reserved for the MeasureSpec mode.
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    }
    else
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

public void setExpanded(boolean expanded)
{
    this.expanded = expanded;
}
}

Gridview子布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/button_pressed_nocolor_all"
    android:gravity="center">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/photo_thumb_calldetails"
    android:padding="5dp"
    android:layout_gravity="center" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/label_photo_name"
    android:textSize="12sp"
    android:layout_gravity="center"
    android:gravity="center"
    android:padding="2dp"
    android:layout_marginBottom="2dp" />

感谢对此的任何帮助。我尝试搜索此类问题,但无法通过提供的任何解决方案来解决。

阿加瓦尔保险柜

将ImageView的高度设置为100dp即可。谢谢 :)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在 UIView 中居中子视图?

来自分类Dev

增加 firebase 数据库中子项中的项目

来自分类Dev

根据父级在CSS中的高度将子项居中

来自分类Dev

相对布局的居中子代

来自分类Dev

如何在类似于GridView的GridLayout中获取选定的子项

来自分类Dev

在父div中具有兄弟姐妹的居中子元素

来自分类Dev

使用自动布局垂直居中子视图

来自分类Dev

选中父复选框不会选中子项

来自分类Dev

具有给定条件的数组中子项的CosmosDB SQL查询

来自分类Dev

如何获取列表中子项目的ID?

来自分类Dev

阵列中子项目的Firebase安全规则

来自分类Dev

将GridView子项与UWP XAML中的单元格顶部对齐

来自分类Dev

使用 Flexbox 垂直居中并对齐子项

来自分类Dev

使用输入子项水平居中div和span居中

来自分类Dev

MVC中的子项加载/选项的淘汰子项

来自分类Dev

如何在不居中子菜单的情况下居中菜单

来自分类Dev

ButtonBox中的同类子项

来自分类Dev

在ExpandableListView中更新子项

来自分类Dev

ExpandableListAdapter中的子项的ContextMenu

来自分类Dev

在AdapterView中查找子项

来自分类Dev

在NSDictionary中查找子项

来自分类Dev

在umbraco中获取子项

来自分类Dev

从 StackPanel 中删除子项

来自分类Dev

离子离子项目右移和居中

来自分类Dev

将绝对位置div标签的子项居中

来自分类Dev

在IE11上将绝对定位的flex子项居中

来自分类Dev

RelativeLayout的子项的垂直位置偏移,该位置垂直居中

来自分类Dev

如何使用 css 将 div 的所有子项垂直居中?

来自分类Dev

解决Play 2 Java Framework中子项目与根项目之间的模板名称冲突