I can set ViewPager's height programatically by using vpTabs.getLayoutParams().height = DESIRED_SIZE;
but it works only once at run time. now the question is how to set the height more than one time at runtime ?
activity_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rlActivityProfile"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.my.package.ProfileActivity">
<!--MainContainer-->
<com.my.package.widget.ScrollViewX
android:id="@+id/svxUserProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Main Container-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Header-->
<RelativeLayout
android:id="@+id/rlProfileBanner"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@color/listile_green">
<!-- SOME OTHER VIEW-->
</RelativeLayout>
<RelativeLayout
android:id="@+id/rlTabs"
android:layout_below="@id/rlProfileBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Slider-->
<android.support.v4.view.ViewPager
android:id="@+id/vpTabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/stlControl" />
</RelativeLayout>
</RelativeLayout>
</com.my.package.widget.ScrollViewX>
<!--Transparent toolbar-->
<include
android:id="@+id/iAppBar"
layout="@layout/app_bar" />
</RelativeLayout>
The viewPager is initialized in onCreate() of MainActivity class
ViewPager vpTabs = (ViewPager) findViewById(R.id.vpTabs);
I am changing the viewPager's height from fragment using an interface like this
//Calling from fragment
int totalHeight = titles.length * EditProfileAdapter.ROW_HEIGHT;
vpListener.onViewPagerHeightChange(totalHeight);
in MainActivity
@Override
public void onViewPagerHeightChange(int height) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.height = height; //left, top, right, bottom
vpTabs.setLayoutParams(params);
}
NOTE: The custom widget ScrollViewX
is the same ScrollView but with a Custom ScrollListener.