2016-06-11 8 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. Если вы не хотите прокручивать вниз, лучше использовать атрибут «вес». Я даю вам представление о том, как реализовать его в вашем коде.

Предположим, что высота всего экрана равна 1. У вас есть изображение и кнопка, чтобы поместить на экран все устройства. Поэтому разделите экран на две части ... 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/>.