我整个晚上都在尝试这个无济于事,所以我将从头开始列出我的确切步骤.
这将是我希望能够创建网格布局的项目.
要设置支持包,这些是我的步骤:
Android的软件开发工具包\演员\机器人\ SUPPORT\V7 \网格布局
testinggridlayout项目,然后单击属性:在此刻
如果我进入main.xml布局,请手动插入以下代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<GridLayout
android:background="#FFFFFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="8"
android:rowCount="5" >
</GridLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我收到错误:
找不到以下类: - GridLayout(修复构建路径,编辑XML).
如果我改变
<GridLayout> & </GridLayout>
至
<android.support.v7.widget.GridLayout> & </android.support.v7.widget.Gridlayout>
我收到同样的错误:
找不到以下类: - android.support.v7.widget.GridLayout(修复构建路径,编辑XML).
那时我在我的项目中创建了一个名为"libs"的文件夹.
然后我将GridLayout项目中libs下的android-support-v7-GridLayout.jar文件复制到该文件夹中.
我在"testinggridlayout"的"libs"文件夹中右键单击了该文件,并选择了"Add to Build Path".
我的错误然后改为:
无法实例化以下类: - android.support.v7.widget.GridLayout(open class,show error log)
我错过了哪些位/不应该做的?
我创建了一个自定义视图,在按下,突出显示或禁用时应该更改它的背景图像.应用程序运行,但按钮不会更改它的背景.
这是我的代码:
public class CustomImageButton extends View {
public CustomImageButton(Context context) {
super(context);
setFocusable(true);
setClickable(true);
}
public CustomImageButton(Context context, AttributeSet attrs) {
super(context, attrs);
setFocusable(true);
setClickable(true);
}
public CustomImageButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setFocusable(true);
setClickable(true);
}
protected Drawable background = super.getBackground();
@Override
public void setBackgroundDrawable(Drawable d) {
// Replace the original background drawable (e.g. image) with a LayerDrawable that
// contains the original drawable slightly edited.
CustomImageButtonBackgroundDrawable layer = new CustomImageButtonBackgroundDrawable(d);
super.setBackgroundDrawable(layer);
}
public void …Run Code Online (Sandbox Code Playgroud)