Android will get screen size in XML

Hi, I have a scroll at the top of the screen to a little to the bottom of the screen, because this is the place where my banner ad takes place. I want to have pixels between these elements (between buttons and banner) due to google policy. So far, I have been doing this with setting a value in dp. But as the devices differ from each other, this leads to a huge gap between the announcement and scrolling on some mobile phones. That is why I would like to install

<ScrollView android:layout_height="(Screen_height-banner)-5px" 

(of course, I have not even tried it this way, since this is not code, but I think it reflects very well what I plan to do)

Thanks so much for your answers!

+8
android layout
source share
3 answers

You cannot request the screen size in XML, because it does not start at run time, you can do this using RelativeLayout and use alignments and margins .

in your case, if Screen_height-banner represents the height of the screen, and you want to place it at the bottom and make the separator 5dp from the end, your XML will be

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_marginBottom="5dp"> </RelativeLayout > 

If you need to scale the scroll view, not the position, then you, xml, would be

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding_bottom="5dp"> <ScrollView android:layout_width="wrap_content" android:layout_height="fill_parent"> </RelativeLayout > 
+2
source share

You can set the weight of the user. If you set the weight of both layouts to 0.5, this will equal the screen width for these layouts.

  <LinearLayout android:id="@+id/alt_panel" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/orta_panel" > <LinearLayout android:id="@+id/altsol_panel" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="0.5" android:gravity="center_horizontal" android:orientation="vertical" > </LinearLayout> <LinearLayout android:id="@+id/altsag_panel" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="0.5" android:gravity="center_horizontal" android:orientation="vertical" > </LinearLayout> </LinearLayout> 
+2
source share

Use RelativeLayout, set 5px margin and use layout_above

+1
source share

All Articles