GridView居中显示和上下留空


实现效果代码,首先上下留空是采用的ScrollView+GridView实现

由于Scrollview和gridview都有滑动条,所以只能采用自定义的gridview去掉其滑动条

package com.wowotuan.pay.quick;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

public class MyGridView extends GridView {

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

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

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

     @Override
     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

         int expandSpec = MeasureSpec.makeMeasureSpec(
                 Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
         super.onMeasure(widthMeasureSpec, expandSpec);
     }

扫描二维码关注公众号,回复: 781277 查看本文章


}

gridview居中显示的方法是在其子类item中设置居中android:gravity="center"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:gravity="center"
  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.wowotuan.view.CreditTextView
android:id="@+id/tv"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/credititemselector"
  android:text="123"
  android:textColor="#393939"
  android:textSize="16sp"
  android:gravity="center"
  />
</LinearLayout>
 

猜你喜欢

转载自605137536.iteye.com/blog/1676657
今日推荐