小编Kyo*_*eko的帖子

为eclipse设置Android支持包v7 - GridLayout

我整个晚上都在尝试这个无济于事,所以我将从头开始列出我的确切步骤.

  • 我已经通过SDK管理器安装了支持包.
  • 我创建了一个新的android项目,我称之为"testinggridlayout".
  • 我选择的构建目标是Android 2.1 API 7.
  • 项目清单

这将是我希望能够创建网格布局的项目.


要设置支持包,这些是我的步骤:

  • 右键单击我刚创建的项目,然后选择 - 新建 - Android项目
  • 将其命名为GridLayout并从现有源中选择create project并浏览到:

Android的软件开发工具包\演员\机器人\ SUPPORT\V7 \网格布局

  • 右键单击我的testinggridlayout项目,然后单击属性:
  • 在Java Build Path下 - 选择Projects选项卡,然后选择Add.
  • 选择我的项目"GridLayout"并单击"确定",然后单击"确定".

在此刻

如果我进入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)

我错过了哪些位/不应该做的?

java eclipse android android-layout

34
推荐指数
3
解决办法
4万
查看次数

自定义视图无法响应触摸

我创建了一个自定义视图,在按下,突出显示或禁用时应该更改它的背景图像.应用程序运行,但按钮不会更改它的背景.

这是我的代码:

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)

android custom-controls touch android-widget android-layout

4
推荐指数
2
解决办法
2359
查看次数