Android:选择xml中包含视图的位置
我正在用游戏卡构建一个应用程序,我正在考虑创建一个自定义视图,该视图有一张普通的卡,卡的正面和背面一旦点击就会从正面到背面翻转 我一直在使用教程,以实现从前到后翻转卡,它的工作完美。但在应用程序上工作了一段时间后,我发现我的应用程序的下一部分会出现严重问题,那就是在屏幕上拖拽卡 今天早上,当我在freenode聊天中与JakeWharton交谈时,我想我应该创建一个XML视图,并将其包含在Android:选择xml中包含视图的位置,android,android-xml,android-view,Android,Android Xml,Android View,我正在用游戏卡构建一个应用程序,我正在考虑创建一个自定义视图,该视图有一张普通的卡,卡的正面和背面一旦点击就会从正面到背面翻转 我一直在使用教程,以实现从前到后翻转卡,它的工作完美。但在应用程序上工作了一段时间后,我发现我的应用程序的下一部分会出现严重问题,那就是在屏幕上拖拽卡 今天早上,当我在freenode聊天中与JakeWharton交谈时,我想我应该创建一个XML视图,并将其包含在main.XML中 问题是,当我尝试移动包含的视图时,我所做的只是将图像粘贴到左上角问题:如何在父视图中移动
main.XML
中
问题是,当我尝试移动包含的视图时,我所做的只是将图像粘贴到左上角问题:如何在父视图中移动包含的xml?
卡的代码:
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="80dp"
android:layout_height="108dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/firstImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/c2" />
<ImageView
android:id="@+id/secondImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/back" />
</ViewFlipper>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Board"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:background="@drawable/pinecropped" >
<include
android:id="@+id/firstCard"
android:layout_marginRight="91dp"
android:layout_marginTop="102dp"
layout="@layout/card" />
</FrameLayout>
以下是我得到的图形布局: 在card.xml中更改:
<ImageView
android:id="@+id/firstImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/c2" />
<ImageView
android:id="@+id/secondImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/back" />
致:
我一直都知道你可以使用这个工具来调试这些问题,我想你会看到这些卡实际上占据了整个屏幕,这就是为什么它们会贴在顶部
更新:
似乎为了覆盖标签中的layout_*属性,您必须同时覆盖layout_高度和layout_宽度,请参见此处的错误和解决方法:
最后,我只是创建了一个不同的类来处理卡片,并在
main.xml
中有一个布局来在主活动代码中表示它。尝试了一下,没有做任何事情:(我会查看hierarchyViewerDidn’你没有在FrameLayout中指定固定大小,所以不是那样。请参阅我对上面答案的更新,以获得可能的解决方案我建议的上述解决方法是否有效?覆盖include元素中的布局宽度和布局高度。不,因为include
将子xml放在框架中布局
这就是所做的更改,对包含的xml文件没有影响
<ImageView
android:id="@+id/firstImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/c2" />
<ImageView
android:id="@+id/secondImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back" />