2017-06-21 125 views
0

我正在開發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,該卡更小。 我懷疑卡片的大小是在旋轉之前計算出來的,然後旋轉會以某種方式縮小它們,看起來左邊的玩家的卡片寬度與頂層玩家的寬度相同,但是由於旋轉,它應該更大。

我該如何旋轉這些卡片,但保持它們的原始尺寸? 謝謝。

下面是遊戲截圖。

Screenshot from the game

+0

https://stackoverflow.com/questions/8981845/android-rotate-image-in-imageview-by-an-angle – RonTLV

回答

0

我懷疑卡的尺寸被旋轉之前計算,然後旋轉縮小他們不知爲什麼...

我認爲這可能是錯誤的。 Android會計算最終的寬度和高度度量,並在佈局中進行調整。因爲它關心的是它最終顯示的內容,它引用了你提到的屬性。

嘗試在寬度或高度或兩者給予wrap_content爲蹦牀網上單人卡在ImageView像 -

android:layout_width="wrap_content" 
android:layout_height="wrap_content" 

還要注意200dp應該容納所有5張牌寬度加上你有填充(2dp每卡)。並且80dp寬度應該包含您的卡片的高度加上2dp填充。否則LinearLayout給予更高的layout_widthlayout_height

+0

嗨,謝謝你的迴應!我嘗試了你所說的,但它似乎沒有改變任何東西 – Billy

+0

嘗試'android:layout_width =「wrap_content」 android:layout_height =「wrap_content」'LinearLayout'可能是? –