2016-06-11 67 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/>

相关问题