具有“翻转”功能的 FrameView动画图像未按比例缩小
似乎无法弄清楚我做错了什么...
我正在构建一个纸牌游戏,其中有一张翻转卡和下面显示信息的一些文本视图。
我有以下 main.xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="6" >
<include
android:id="@+id/frameview1"
layout="@layout/first_card" />
<include
android:id="@+id/frameview2"
layout="@layout/second_card" />
</FrameLayout>
<TextView
android:id="@+id/text_mainMessage"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="2"
android:text="@string/resetMessage"
android:textColor="#FF0000"
android:textSize="23sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_subMessage"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="2.5"
android:minLines="3"
android:textColor="#FFFFFF"
android:textSize="16sp" />
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="@+id/text_cardsRemainingLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:text="@string/cardsRemainingLabel"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="@+id/text_cardsRemaining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/text_cardsRemainingLabel"
android:layout_marginLeft="2dip"
android:layout_toRightOf="@id/text_cardsRemainingLabel"
android:text="@string/cardsRemainingInitial"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="@+id/text_kings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/text_cardsRemainingLabel"
android:layout_marginRight="10dip"
android:text="@string/kingsInitial"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="@+id/text_kingsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/text_cardsRemainingLabel"
android:layout_marginRight="2dip"
android:layout_toLeftOf="@id/text_kings"
android:text="@string/kingsLabel"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
我还有以下两个 XML 文件,根据 http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/btn_card"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_margin="5dip"
android:layout_gravity="center"
android:scaleType="centerInside"
android:layout_weight="6"
android:background="@drawable/empty"
android:contentDescription="@string/cardImageDesc"
android:src="@drawable/card_back_rof" />
</LinearLayout>
(first_card.xm 和 secondary_card.xml 是相同的,除了id 值)
现在解决问题: 我使用的图像文件高约 350 像素,尽管在我的主 LinearLayout
上使用了 layout_weight
,但它并没有缩小以适合我的屏幕。
我已经尝试在我能想到的每个地方使用 maxHeight
值,但这并没有起作用,而且 - 当我感觉时,我不想将硬编码的像素限制放入视图中就像它应该自动调整大小一样。
非常感谢任何帮助!
谢谢,
马克
Can't seem to work out what I've got wrong...
I've got a card game I'm building with a flipping turn over card and some text views below that display information.
I have the following main.xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="6" >
<include
android:id="@+id/frameview1"
layout="@layout/first_card" />
<include
android:id="@+id/frameview2"
layout="@layout/second_card" />
</FrameLayout>
<TextView
android:id="@+id/text_mainMessage"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="2"
android:text="@string/resetMessage"
android:textColor="#FF0000"
android:textSize="23sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_subMessage"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="2.5"
android:minLines="3"
android:textColor="#FFFFFF"
android:textSize="16sp" />
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="@+id/text_cardsRemainingLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:text="@string/cardsRemainingLabel"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="@+id/text_cardsRemaining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/text_cardsRemainingLabel"
android:layout_marginLeft="2dip"
android:layout_toRightOf="@id/text_cardsRemainingLabel"
android:text="@string/cardsRemainingInitial"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="@+id/text_kings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/text_cardsRemainingLabel"
android:layout_marginRight="10dip"
android:text="@string/kingsInitial"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="@+id/text_kingsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/text_cardsRemainingLabel"
android:layout_marginRight="2dip"
android:layout_toLeftOf="@id/text_kings"
android:text="@string/kingsLabel"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
I also have the following two XML files that hold the card images for "pre" and "post" flip within the FrameView as per http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/btn_card"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_margin="5dip"
android:layout_gravity="center"
android:scaleType="centerInside"
android:layout_weight="6"
android:background="@drawable/empty"
android:contentDescription="@string/cardImageDesc"
android:src="@drawable/card_back_rof" />
</LinearLayout>
(The first_card.xm land second_card.xml are identical save for the id value)
Now for the problem:
The image files I am using are about 350 pixels tall and despite using the layout_weight
on my main LinearLayout
this is not scaling down to fit on my screen.
I've tried using maxHeight
values in every place I can think of it, but that hasn't worked, and besides - I don't want to put hard coded pixel limits into the view when I feel like it should all resize itself automatically.
Any help greatly appreciated!
Thanks,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论