实现效果代码,首先上下留空是采用的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);
}
}
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>