我只是想延長的ImageView:Android的 - 無法擴展的ImageView
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
public class SquareImageView extends ImageView {
public SquareImageView(Context context) {
super(context);
}
public SquareImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
setMeasuredDimension(width, width);
}
}
但是Android工作室返回編譯錯誤:
This custom view should extend android.support.v7.widget.AppCompatImageView instead
但進口android.support.v7.widget.AppCompatImageView
insted的的android.widget.ImageView
沒有解決,因爲問題ImageView被標記爲未導入...
我在做什麼錯在這裏?
你也必須改變'extends'部分;不只是'import' - '公共類SquareImageView擴展了AppCompatImageView'。 –
'SquareImageView extneds android.support.v7.widget.AppCompatImageView' –