Images Disappear When Read More Button Is Clicked?
I created a ScrollView and added two LinearLayouts inside one big LinearLayout and have given weights for those.The problem is that it shows my images of the image slider at initia
Solution 1:
As I commented before, your logic will not work properly, because giving vertical weight inside a ScrollView
causes calculation problems.
So you should not use need any weight to resize your ViewPager
content width.
If you have certain width/height ratio, resize it programmatically like below. Write these lines inside of onCreate(), after findViewById
:
UPDATE You can get scrollView height like this :
viewPager = (ViewPager) rootView.findViewById(R.id.viewPager);
ViewTreeObservervto= scrollView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(newOnGlobalLayoutListener() {
@OverridepublicvoidonGlobalLayout() {
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
intscrollViewHeightInPixels= layout.getMeasuredHeight();
//This is equal with %45 weight you tried beforeintheight= (scrollViewHeightInPixels * 45) / 100;
ViewGroup.LayoutParamspagerParams= viewPager.getLayoutParams();
pagerParams.height = height;
}
});
Then remove unnecessary layouts and change your layout like below:
200 dp on viewPager height is for fixed height at start, wrap_content and match_parent sometimes causes problems
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><android.support.v4.view.ViewPagerandroid:id="@+id/viewPager"android:layout_width="match_parent"android:layout_height="200dp" /><LinearLayoutandroid:id="@+id/SliderDots"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignBottom="@id/viewPager"android:layout_marginBottom="20dp"android:gravity="center_horizontal"android:orientation="horizontal" /></RelativeLayout><TextViewandroid:id="@+id/aboutsltext"android:layout_width="match_parent"android:layout_height="wrap_content"android:maxLines="3"android:text="Sri Lanka (formerly Ceylon) is an island nation south of India in the Indian Ocean. Its diverse landscapes range from rainforest and arid plains to highlands and sandy beaches. It’s famed for its ancient Buddhist ruins, including the 5th-century citadel Sigiriya, with its palace and frescoes. The city of Anuradhapura, Sri Lanka's ancient capital, has many ruins dating back more than 2,000 years. Sri Lanka (formerly Ceylon) is an island nation south of India in the Indian Ocean. Its diverse landscapes range from rainforest and arid plains to highlands and sandy beaches. It’s famed for its ancient Buddhist ruins, including the 5th-century citadel Sigiriya, with its palace and frescoes. The city of Anuradhapura, Sri Lanka's ancient capital, has many ruins dating back more than 2,000 years. "android:textColor="@color/colorPrimary"android:textSize="22sp" /><Buttonandroid:id="@+id/readmorebtn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:background="@drawable/readmorebtn"android:text="Read More"android:textAllCaps="false"android:textColor="@color/colorPrimary" /></LinearLayout></ScrollView>
Post a Comment for "Images Disappear When Read More Button Is Clicked?"