我想把图像作为布局的背景.
首先,我正在创建一个drawable: Drawable d = Drawable.createFromPath("pathToImageFile");
在API级别8 layout.setBackground( d )的不支持和 layout.setBackgroundDrawable( d ) 不推荐使用 ,所以我需要使用
layout.setBackgroundResource(resourceID)
如何获取动态生成的drawable的resourceID.我正在使用此方法:
Drawable d = Drawable.createFromPath("pathToImageFile");
创造一个可绘制的.
我想禁用RecyclerView的滚动.为此,我试图MyRecyclerView通过扩展来定义自定义RecyclerView.
MyRecyclerView.java
package com.example;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
class MyRecyclerView extends RecyclerView {
private boolean scrollable = true;
public MyRecyclerView(Context context) {
super(context);
}
public void setScrollingEnabled(boolean scrollable) {
this.scrollable = scrollable;
}
public boolean isScrollable() {
return scrollable;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// if we can scroll pass the event to the superclass
if (scrollable) return super.onTouchEvent(ev);
// only continue to handle the touch event …Run Code Online (Sandbox Code Playgroud) android extend android-custom-view android-5.0-lollipop android-recyclerview