欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

随笔(二十八)

程序员文章站 2024-01-04 15:45:40
...

https://github.com/cundong/HeaderAndFooterRecyclerView
2.
给Grid方式排列的RecyclerView添加间距

https://blog.csdn.net/laxian2009/article/details/72824594

https://www.jb51.net/article/86235.htm

https://blog.csdn.net/lmj623565791/article/details/45059587
3.header的RecyclerView右侧没占满

header = LayoutInflater.from(SearchActivity.this).inflate(R.layout.layout_search_main, (ViewGroup) findViewById(android.R.id.content), false);
//header = ViewGroup.inflate(SearchActivity.this, R.layout.layout_search_main, null);

https://blog.csdn.net/ccfcccfc/article/details/40984971

public class DividerGridItemDecoration extends RecyclerView.ItemDecoration
{

private Drawable mDivider;

public DividerGridItemDecoration(Context context)
{
    mDivider = ContextCompat.getDrawable(context, R.drawable.divider_quote_dark);
}

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
{

    drawHorizontal(c, parent);
    drawVertical(c, parent);

}

private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}

public void drawHorizontal(Canvas c, RecyclerView parent)
{
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++)
    {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getLeft() - params.leftMargin;
        final int right = child.getRight() + params.rightMargin
                + mDivider.getIntrinsicWidth();
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}

public void drawVertical(Canvas c, RecyclerView parent)
{
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++)
    {
        final View child = parent.getChildAt(i);

        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int top = child.getTop() - params.topMargin;
        final int bottom = child.getBottom() + params.bottomMargin;
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicWidth();

        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}

private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount)
{
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL)
        {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else
        {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}

private boolean isLastRaw(RecyclerView parent, int pos, int spanCount,
                          int childCount)
{
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
            return true;
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        // StaggeredGridLayoutManager 且纵向滚动
        if (orientation == StaggeredGridLayoutManager.VERTICAL)
        {
            childCount = childCount - childCount % spanCount;
            // 如果是最后一行,则不需要绘制底部
            if (pos >= childCount)
                return true;
        } else
        // StaggeredGridLayoutManager 且横向滚动
        {
            // 如果是最后一行,则不需要绘制底部
            if ((pos + 1) % spanCount == 0)
            {
                return true;
            }
        }
    }
    return false;
}

@Override
public void getItemOffsets(Rect outRect, int itemPosition,
                           RecyclerView parent)
{
    int spanCount = getSpanCount(parent);
    int childCount = parent.getAdapter().getItemCount();
    if (isLastRaw(parent, itemPosition, spanCount, childCount))// 如果是最后一行,则不需要绘制底部
    {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    } else if (isLastColum(parent, itemPosition, spanCount, childCount))// 如果是最后一列,则不需要绘制右边
    {
        outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
    } else
    {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(),
                mDivider.getIntrinsicHeight());
    }
}

}

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






4.
理解Android Architecture Components系列(一)

https://www.jianshu.com/p/42eb71ec4a19
https://xuyonghong.cn/2018/09/03/Android-JetPack-ViewModel/
5.带箭头的popwindow列表
https://github.com/zyyoona7/EasyPopup

http://www.jcodecraeer.com/a/opensource/2017/0810/8363.html

mQQPop = EasyPopup.create()
.setContext(this)
.setContentView(R.layout.layout_right_pop)
.setAnimationStyle(R.style.RightTop2PopAnim)
.setOnViewListener(new EasyPopup.OnViewListener() {
@Override
public void initViews(View view, EasyPopup basePopup) {
View arrowView = view.findViewById(R.id.v_arrow);
arrowView.setBackground(new TriangleDrawable(TriangleDrawable.TOP, Color.parseColor("#88FF88")));
}
})
.setFocusAndOutsideEnable(true)
// .setBackgroundDimEnable(true)
// .setDimValue(0.5f)
// .setDimColor(Color.RED)
// .setDimView(mTitleBar)
.apply();

<View
    android:id="@+id/v_arrow"
    android:layout_width="20dp"
    android:layout_height="10dp"
    android:layout_gravity="start"
    android:layout_marginEnd="10dp"
    android:layout_marginRight="10dp"/>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#88FF88"
    android:divider="@drawable/divider_horizontal_bg"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:showDividers="middle">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        android:gravity="center"
        android:text="one"
        android:textSize="14sp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="center"
        android:text="two"
        android:textSize="14sp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="center"
        android:text="three"
        android:textSize="14sp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="center"
        android:text="four"
        android:textSize="14sp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="center"
        android:text="five"
        android:textSize="14sp"/>
</LinearLayout>
6.悬浮窗 https://github.com/yhaolpz/FloatWindow 7.矢量图 Android使用矢量图(SVG, VectorDrawable)实践篇

https://www.jianshu.com/p/0555b8c1d26a