Android: Layout always 2/3 screen -


i have many views i'm adding in scroll view (by <include> ). these layouts this:

<relativelayout         android:id="@+id/one"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         app:layout_constrainttop_totopof="parent"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_torightof="parent"         app:layout_constraintbottom_tobottomof="parent"         android:layout_margintop="10dp"         android:layout_marginbottom="10dp"         android:layout_marginleft="18dp"         android:layout_marginright="18dp" > </relativelayout> 

this how include layouts fragment layout:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"               android:orientation="vertical"               android:layout_width="match_parent"               android:layout_height="wrap_content" >     <scrollview android:layout_width="match_parent" android:layout_height="match_parent">         <linearlayout android:layout_width="wrap_content"                       android:layout_height="wrap_content"                       android:orientation="vertical"         >             <include layout="@layout/one"/>             <include layout="@layout/two"/>             <include layout="@layout/three"/>         </linearlayout>         </scrollview> </linearlayout> 

how make 3 layouts take height 2/3 of screen. want have @ 2/3 of screen on each device. layout_weight doesn't work intended.

you can width , height of screen in mulitple way

public static int getscreenwidth() {     return resources.getsystem().getdisplaymetrics().widthpixels; }  public static int getscreenheight() {     return resources.getsystem().getdisplaymetrics().heightpixels; } 

getscreenheight() return total height

you can use height , set params follows:

desired_height_params = getscreenheight() *2/3  relativelayout.layoutparams lp = new relativelayout.layoutparams(     relativelayout.layoutparams.wrap_content,      desired_height_params ); linlayout.setlayoutparams(lp); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -