我有顶部viewpager和另一个vew(在这个例子中的按钮)底部的线性布局。寻呼机中的视图具有不同的高度。我希望寻呼机在所有页面上都有wrap_content
高度,按钮视图可以填充屏幕的其余部分。android UI - viewpager的wrap_content
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="New Button"
android:id="@+id/button3"
android:layout_weight="1"/>
</LinearLayout>
这是行不通的。如果我给页面和按钮分配layout_weight=1
,则无论内容高度如何,它们都共享屏幕50:50。我试图在ViewPager.OnPageChangeListener.onPageSelected()
中拨打requestLayout()
,但它没有帮助。也试过this
找到[this](http://stackoverflow.com/questions/8394681/android-i-am-unable-to-have-viewpager-wrap-content)问题,这似乎是解决方案的一半。唯一的问题是如何实现ViewPager的后代以仅测量当前页面。我发现它相当困难,一切都是私密的。 –
我对你提供的SO问题进行了回答,请检查https://github.com/rnevet/WCViewPager的实现应该解决你的请求。 – Raanan