在LinearLayout中旋转ImageView的
我正在开发Android卡牌游戏。 我想显示所有玩家卡,所以我创建了4个LinearLayouts。 1为*玩家,左侧玩家,右侧玩家和底部玩家。在LinearLayout中旋转ImageView的
我想为卡片使用相同的图像,因此我尝试旋转侧边玩家(左侧和右侧玩家)的卡片。
由于某些原因,顶牌和底牌玩家牌看起来不错,但是边牌玩家牌太小。
这是我的左手球员布局:
<LinearLayout
android:id="@+id/leftParentLayout"
android:layout_width="80dp"
android:layout_height="200dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.026"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.381">
<ImageView
android:id="@+id/player_left_card_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:clickable="false"
android:paddingBottom="1dp"
android:paddingEnd="1dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:rotation="90" />
<ImageView
android:id="@+id/player_left_card_5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:clickable="false"
android:paddingBottom="1dp"
android:paddingEnd="1dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:rotation="90" />
<ImageView
android:id="@+id/player_left_card_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:clickable="false"
android:paddingBottom="1dp"
android:paddingEnd="1dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:rotation="90" />
<ImageView
android:id="@+id/player_left_card_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:clickable="false"
android:paddingBottom="1dp"
android:paddingEnd="1dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:rotation="90" />
<ImageView
android:id="@+id/player_left_card_4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:clickable="false"
android:paddingBottom="1dp"
android:paddingEnd="1dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:rotation="90" />
</LinearLayout>
虽然高度应为200,宽度80,该卡更小。 我怀疑卡片的大小是在旋转之前计算出来的,然后旋转会以某种方式缩小它们,看起来左边的玩家的卡片宽度与顶层玩家的宽度相同,但是由于旋转,它应该更大。
我该如何旋转这些卡片,但保持它们的原始尺寸? 谢谢。
下面是游戏截图。
我怀疑卡的尺寸被旋转之前计算,然后旋转缩小他们不知为什么...
我认为这可能是错误的。 Android会计算最终的宽度和高度度量,并在布局中进行调整。因为它关心的是它最终显示的内容,它引用了你提到的属性。
尝试在宽度或高度或两者给予wrap_content
为蹦床网上单人卡在ImageView
像 -
android:layout_width="wrap_content"
android:layout_height="wrap_content"
还要注意200dp
应该容纳所有5张牌宽度加上你有填充(2dp
每卡)。并且80dp
宽度应该包含您的卡片的高度加上2dp
填充。否则LinearLayout
给予更高的layout_width
和layout_height
。
嗨,谢谢你的回应!我尝试了你所说的,但它似乎没有改变任何东西 – Billy
尝试'android:layout_width =“wrap_content” android:layout_height =“wrap_content”'LinearLayout'可能是? –
https://*.com/questions/8981845/android-rotate-image-in-imageview-by-an-angle – RonTLV