我扩展了 LinearLayout
并创建了我自己的类 GameLinerLayout
,然后我创建了扩展该类 GameLinerLayout
的类 LudoGame
>.
现在我尝试在我的布局“main.xml”中使用它
<android.game.ludo.LudoGame xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_absolute"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background">
</android.game.ludo.LudoGame>
但我不能让它工作“背景”参数。那么如何在我自己的view上设置背景图片呢?
我不明白这个。我有我的布局,我只想在该 View 上设置背景(没有其他 View ),如果我这样做
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/wood">
<android.game.ludo.LudoGame xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_absolute"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</android.game.ludo.LudoGame>
</LinearLayout>
它不显示任何内容,如果我在“LudoGame”布局上设置“android:background="#FFFFFF"",那么我会看到内容但没有背景。你能告诉我一些如何解决这个问题的例子吗?
谢谢。
这与我的 Layout 工作方式相同 GameLinerLayout extends LinearLayout 我@Override onDraw 方法对象 Canvas 在哪里,我在哪里绘制内容
@Override
protected void onDraw(Canvas canvas)
{
super.dispatchDraw(canvas);
drawFields(canvas);
}
但我不想用 Canvas 绘制背景图像,我想(如果可能的话)在尝试定义(使用)我的布局时在 XML 中设置该背景
最佳答案
在里面再取一个线性布局。它会起作用。因为你没有在你的扩展类中定义任何背景属性,所以你最好在其中放置另一个线性布局,其中包含 fill_parent 宽度和高度。!!
关于安卓我的LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7399430/