简体   繁体   中英

Android not scaling my layouts?

I thought android automatically be default will scale your layouts? Well to put in respective, I have a ViewPager with 4 pages. The ViewPager is placed in the center, while a header like button takes the top as well as a footer like button occupies the bottom. All three of these views are seperate.

The application on my phone looks great, but when I test it on a friends phone, the ViewPager loses its height. I have a height of 310dp and width of match_parent. So when my application runs on my friends phone which is longer in portrait height, why does my ViewPager not meet my footer like it does on my phone?

Please and thank you!

Is your layout LinearLayout? Then your ViewPager should have layout_weight=1, and layout_height=0dp.

When you specify the height, Android uses the height you specify. If you're using relative layouts and aligning top and bottom, then you will have a space somewhere.

Also, you need to consider aspect ratio. If your friend's phone has more vertical pixels than yours, do you want the gap or do you want stretched images? With all the devices out there, this is a very important question.

Read up on this: http://ugiagonzalez.com/2012/01/19/android-linearlayout-distribution-explained-weight-and-sizes/

and this: Button size and padding within RelativeLayout

To Run your application successfully on all mobile phones ,you can use layout weight property for wrapping your whole layout in linear layout like

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
         android:text="@string/header" />
  <ViewPager
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="@string/send" />
</LinearLayout>

with this your layout fit on all screens

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM