我试图创建我的第一个真正的Android应用程序中,code似乎很容易,但布局是给我的问题。
我的应用程序将是一个拖放应用程序,非常简单,只需将形状到正确的地方,在谜。下面是它的外观,现在一个例子:
我目前有4 的ImageView
S,一个是空之谜的顶部,然后各1以下的形状。 我觉得以做正确的方法是让每个谜题的空点是的ImageView
(什么箭头指向,例如,应该是一个的ImageView
)
如果我是正确的关于这一点,我需要图层的ImageView
S,把3空形像欣赏谜图像视图顶部。问题是我找不到任何的例子或建议的任何地方上网。所以我的问题是:
的ImageView
也是坐着上的背景的ImageView
,或者是顶有一个更正确的方式做到这一点?如果我在正确的方向也得走,能不能有人解释/ examplify怎么一建的ImageView
层?XML我目前的屏幕:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android 的xmlns:工具=http://schemas.android.com/tools 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT 机器人:方向=垂直> < ImageView的 机器人:ID =@ + ID / emptyPuz 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:SRC =@绘制/ EmptyPuzzle/> <的LinearLayout 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT 机器人:方向=horizantal> < ImageView的 机器人:ID =@ + ID / imageView1 机器人:layout_width =0dp 机器人:layout_weight =1 机器人:layout_height =WRAP_CONTENT 机器人:adjustViewBounds =假 机器人:SRC =@绘制/圈/> < ImageView的 机器人:ID =@ + ID / imageView2 机器人:layout_width =0dp 机器人:layout_weight =1 机器人:layout_height =WRAP_CONTENT 机器人:adjustViewBounds =假 机器人:SRC =@绘制/坊/> < ImageView的 机器人:ID =@ + ID / imageView3 机器人:layout_width =0dp 机器人:layout_weight =1 机器人:layout_height =WRAP_CONTENT 机器人:adjustViewBounds =假 机器人:SRC =@绘制/三角/> < / LinearLayout中>< / LinearLayout中>
解决方案
我结束了使用该解决方案的已的添加一个新的的LinearLayout
与在背景
设置为谜基地的形象,并增加了三个新的图像,上面有空之谜片。即:我分手了每个3空之谜插槽分成单独的图像就像这个例子:
然后用它们作为背景,以一个新的布局,所以在这里我以前出现过此code:
< ImageView的 机器人:ID =@ + ID / emptyPuz 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:SRC =@绘制/ EmptyPuzzle/>
我现在有:
<的LinearLayout 机器人:layout_width =FILL_PARENT 机器人:layout_height =0dp 机器人:layout_weight =1 机器人:背景=@绘制/ emptypuzzle 机器人:方向=横向> < ImageView的 机器人:ID =@ + ID / dropsquare 机器人:layout_width =0dp 机器人:layout_weight =1 机器人:标签=广场 机器人:layout_height =WRAP_CONTENT 机器人:adjustViewBounds =假 机器人:SRC =@绘制/ emptysquare/> < ImageView的 机器人:ID =@ + ID / droptriangle 机器人:layout_width =0dp 机器人:layout_weight =1 机器人:标签=三角 机器人:layout_height =WRAP_CONTENT 机器人:adjustViewBounds =假 机器人:SRC =@绘制/ emptytriangle/> < ImageView的 机器人:ID =@ + ID / dropcircle 机器人:layout_width =0dp 机器人:layout_weight =1 机器人:标签=圈 机器人:layout_height =WRAP_CONTENT 机器人:adjustViewBounds =假 机器人:SRC =@绘制/ emptycircle/>< / LinearLayout中>
与最终拖累结束拖放游戏看起来像:
这不是pretty,但我的孩子喜欢它。 :)
I'm trying to create my first real Android app, the code seems easy enough, but the layout is giving me problems.
My app will be a drag and drop application, very simple, just drag shapes to the correct place in the "puzzle". Here's an example of how it looks right now:
What I have currently is 4 ImageView
s, one for the "empty puzzle" at the top, then 1 for each of the shapes below. I think the correct way to do this is to have each of the empty spots in the puzzle be an ImageView
(what the arrow is pointing to, for example, should be an ImageView
)
If I am correct on this, I need to "layer" ImageView
s, put 3 "empty shape" image views over the "puzzle" image view at the top. The problem is I can't find any examples or suggestions for this anywhere online. So my questions are:
ImageView
s sitting on top of a "background" ImageView
, or is there a more correct way to do this?
If I'm heading in the right direction, could someone explain/examplify how one builds ImageView
layers?
XML for my current screen:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/emptyPuz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/EmptyPuzzle" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizantal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:src="@drawable/Circle" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:src="@drawable/Square" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:src="@drawable/Triangle" />
</LinearLayout>
</LinearLayout>
解决方案
The solution I ended up using was to add a new LinearLayout
with the background
set to a "puzzle base" image and added three new images with "empty puzzle" pieces on it. Ie: I broke up each of the 3 "empty" puzzle slots into individual images like in this example:
Then used them as backgrounds to a new layout, so where I had this code before:
<ImageView
android:id="@+id/emptyPuz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/EmptyPuzzle" />
I now have:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/emptypuzzle"
android:orientation="horizontal" >
<ImageView
android:id="@+id/dropsquare"
android:layout_width="0dp"
android:layout_weight="1"
android:tag="square"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:src="@drawable/emptysquare" />
<ImageView
android:id="@+id/droptriangle"
android:layout_width="0dp"
android:layout_weight="1"
android:tag="triangle"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:src="@drawable/emptytriangle" />
<ImageView
android:id="@+id/dropcircle"
android:layout_width="0dp"
android:layout_weight="1"
android:tag="circle"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:src="@drawable/emptycircle" />
</LinearLayout>
Ending with a resultant drag and drop game looking like:
It's not pretty, but my toddler likes it. :)
上一篇:Node.js的返回null推送消息消息、Node、js、null
下一篇:在使用的RelativeLayout用的LayoutParams DPRelativeLayout、LayoutParams、DP