2016-06-11 68 views
0

我似乎無法找到一種方法將照片放到我的主頁屏幕上,我嘗試了許多不同的方式,但沒有成功。我有一個圖像,推動它下面的佈局,並擠壓屏幕上的按鈕。有什麼辦法可以自動調整不同屏幕的高度嗎?我只需要高度,因爲寬度應該是match_parent。以下是xml文件。如何調整所有Android設備的屏幕大小

<?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:background="@color/white" 
 
    android:orientation="vertical" 
 
    > 
 

 
    <RelativeLayout 
 
     android:id="@+id/headerLayout" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="?android:attr/actionBarSize" 
 
     android:background="@drawable/nav_bar_homepage" > 
 

 
     <TextView 
 
      android:id="@+id/pageTitle" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_centerInParent="true" 
 
      android:text="WELCOME!" /> 
 

 
     <ImageView 
 
      android:id="@+id/hiddenIcDrawer" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_alignParentTop="true" 
 
      android:layout_marginTop="10dp" 
 
      android:src="@drawable/nav_icon" 
 
      android:visibility="invisible" /> 
 
    </RelativeLayout> 
 

 
    <ImageView 
 
     android:id="@+id/horLine" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:layout_below="@+id/headerLayout" 
 
     android:scaleType="center" 
 
     android:src="@drawable/line_big_white" /> 
 

 
    <RelativeLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:layout_marginBottom="10dp" 
 
     android:scaleType="fitStart" > 
 

 
     <ImageView 
 
      android:id="@+id/image_homepage_id" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:layout_alignParentLeft="true" 
 
      android:layout_gravity="center_horizontal" 
 
      android:src="@drawable/image_homepage" 
 
      /> 
 
    </RelativeLayout> 
 

 
    <LinearLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:layout_alignParentBottom="true" 
 
     android:layout_gravity="center" 
 
     android:layout_margin="10dp" 
 
     android:layout_marginLeft="10dp" 
 
     android:layout_marginRight="10dp" 
 
     android:background="@drawable/field_red_homepage" 
 
     android:orientation="vertical" 
 
     android:scaleType="fitXY" > 
 

 
     <ImageView 
 
      android:id="@+id/logo_homep" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="80dp" 
 
      android:layout_gravity="center" 
 
      android:layout_marginBottom="10dp" 
 
      android:layout_marginTop="5dp" 
 
      android:paddingBottom="10dp" 
 
      android:scaleType="fitXY" 
 
      android:src="@drawable/logo_homepage" /> 
 

 
     <ImageView 
 
      android:id="@+id/redeembytton" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_gravity="center_horizontal" 
 
      android:layout_margin="10dp" 
 
      android:layout_marginLeft="10dp" 
 
      android:layout_marginRight="10dp" 
 
      android:background="@drawable/btn_redeemrewards" 
 
      android:scaleType="fitXY" > 
 
     </ImageView> 
 

 
     <ImageView 
 
      android:id="@+id/orderbutton" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_gravity="center_horizontal" 
 
      android:layout_margin="10dp" 
 
      android:layout_marginLeft="10dp" 
 
      android:layout_marginRight="10dp" 
 
      android:layout_marginTop="15dp" 
 
      android:background="@drawable/btn_orderonline" 
 
      android:scaleType="fitXY" > 
 
     </ImageView> 
 

 
     <ImageView 
 
      android:id="@+id/rewardsButton" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_gravity="center_horizontal" 
 
      android:layout_margin="10dp" 
 
      android:layout_marginLeft="10dp" 
 
      android:layout_marginRight="10dp" 
 
      android:layout_marginTop="15dp" 
 
      android:background="@drawable/btn_earnrewards" 
 
      android:scaleType="fitXY" > 
 
     </ImageView> 
 

 
     <ImageView 
 
      android:id="@+id/referFriendButton" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_gravity="center_horizontal" 
 
      android:layout_margin="10dp" 
 
      android:layout_marginBottom="5dp" 
 
      android:layout_marginLeft="10dp" 
 
      android:layout_marginRight="10dp" 
 
      android:layout_marginTop="15dp" 
 
      android:background="@drawable/btn_referafriend" 
 
      android:scaleType="fitXY" > 
 
     </ImageView> 
 
    </LinearLayout> 
 

 
</LinearLayout>

回答

0

將您的xml代碼包裝到ScrollView如果您可以向下滾動以在ImageView下達到您的內容。如果你不想向下滾動,最好使用「weight」屬性。我正在給你一個想法,如何在你的代碼中實現它。

讓我們假設整個屏幕的高度是1.您有一個圖像和一個按鈕,可以放在所有設備的屏幕上。因此,將屏幕分爲兩部分:imageview爲0.8,按鈕爲0.2。你可以使用下面的代碼來獲得這個結果。

<?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" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" <!-- Important > 
     android:orientation="vertical" 
     android:layout_weight=".8" > <!-- 80% of your screen size> 

     <!-- Your ImageView > 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" <!-- Important > 
     android:orientation="vertical" 
     android:layout_weight=".2" > <!-- 20% of your screen size> 

     <!-- Your Button > 

    </LinearLayout> 

</LinearLayout> 
+0

謝謝你的幫助:D,我去的重量選項,因爲scrollview不允許在主頁上 – Katherina

0

試試這個

我認爲你應該使用 android:layout-weight="1"根據不同devices.use調整它的高度在<ImageLayout/>

相關問題