2015-08-27 40 views
0

更改屏幕方向時,我遇到了問題。當在縱向模式中的手機一切工作正常,但是當我將方向更改爲橫向模式時,imageview隱藏按鈕波紋管。android更改方向時,Imageview隱藏下面的元素

這裏是我的佈局XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity" 
android:longClickable="false"> 


<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Your Inbox" 
    android:id="@+id/btn_inbox" 
    android:layout_centerHorizontal="true" /> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView" 
    android:layout_below="@+id/btn_inbox" 
    android:scaleType="fitCenter" 
    android:adjustViewBounds="true" 
    android:src="@drawable/img_main" /> 

<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Scan QR" 
    android:id="@+id/btn_qrscan" 
    android:layout_below="@+id/imageView" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentEnd="true" 
    android:enabled="false" /> 

回答

1

當然,因爲圖像能有一個適合的尺寸屏幕的肖像。如果你想查看所有,你需要:

  • 減少ImageView的
  • 播放與組件的財產「權重」的大小在視圖
  • 添加滾動型,如果你想使用滾動
+0

重量屬性僅用於LinearLayout中。我嘗試過,但如果我使用固定的佈局重量它可能在景觀上工作,但不適用於肖像模式,因爲它應該。也許我應該改變方向改變時通過代碼?最佳做法是什麼?謝謝 – Mike

0

這是因爲縱向模式中屏幕的高度與橫向模式下屏幕的高度相比更高。元素不會根據屏幕高度自動調整其位置。您應該處理所有方向/設備/平板電腦上的視圖佈局。

當設備處於橫向模式時,寬度更大。因此,嘗試改變視圖的位置以在高度較小時使用寬度。

0

請試試這個

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:longClickable="false" 
    android:orientation="vertical" 
    tools:context=".MainActivity"> 
    <Button 
     android:id="@+id/btn_inbox" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:text="Your Inbox" /> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:src="@drawable/background" /> 

    <Button 
     android:id="@+id/btn_qrscan" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:enabled="false" 
     android:text="Scan QR" /> 


</LinearLayout> 
+0

感謝您的回覆。我嘗試過,但後來當我從風景改變爲肖像模式時,它仍然沒有正確顯示,差距太大。有沒有一種方法可以在保持正確比例的同時適合所有屏幕? – Mike

+0

我用新的xml進行了更新。你可以嘗試這與imageview重量= 1 – Pratap

+0

創建一個相同的佈局文件具有相同的名稱,並把它放在layout-land文件夾與景觀設計相同的組件 – Pratap