gpt4 book ai didi

android - ScrollView 内的 TabLayout+ViewPager

转载 作者:搜寻专家 更新时间:2023-11-01 09:42:19 24 4
gpt4 key购买 nike

我试图让这个页面向下滚动,但现在只有 ViewPager 中的内容在滚动,而不是整个页面。我想让整个页面从顶部向下滚动,但现在它只滚动 ViewPager 中的 ListView

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/asa"
android:scrollbars="vertical"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:mstb="http://schemas.android.com/apk/res-auto"

tools:context="geob.com.testjson.Profile">
<ImageView
android:id="@+id/cover12"
android:src="@drawable/asc"
android:layout_width="fill_parent"
android:layout_height="180dp"
android:scaleType="fitXY" />

<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/ddd"
android:src="@android:drawable/star_big_on"
android:layout_marginBottom="62dp"

android:layout_above="@+id/tab_layout"
android:layout_centerHorizontal="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Taaran"
android:textColor="@android:color/white"
android:id="@+id/dpname"
android:layout_above="@+id/dpuname"
android:layout_alignLeft="@+id/ddd" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\@taaran"
android:textColor="@android:color/white"
android:id="@+id/dpuname"
android:layout_above="@+id/tab_layout"
android:layout_alignLeft="@+id/ddd"
android:layout_alignStart="@+id/ddd"
android:layout_marginBottom="32dp" />


<!-- <android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_below="@+id/cover"
android:layout_alignLeft="@+id/cover"
android:layout_alignStart="@+id/cover" /> -->

<!-- View pager to swipe views -->
<!-- <android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"/> -->
<!--<org.honorato.multistatetogglebutton.MultiStateToggleButton
android:id="@+id/mstb_multi_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
mstb:values="@array/planets_array"
mstb:mstbPrimaryColor="@android:color/holo_blue_dark"
mstb:mstbSecondaryColor="@color/gray_very_light"
android:layout_below="@+id/cover"

/>-->
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_below="@+id/cover12"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/tab_layout"/>

<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/l12"
android:layout_below="@+id/tab_layout"
/>
<com.ashokvarma.bottomnavigation.BottomNavigationBar
android:layout_gravity="bottom"
android:id="@+id/bottom_navigation_bar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Follow"
android:id="@+id/followButton"
android:layout_above="@+id/tab_layout"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

</RelativeLayout>
</ScrollView>

enter image description here

最佳答案

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for (int i = 0; i < getChildCount(); ++i) {
View child = getChildAt(i);
child.measure(widthMeasureSpec,
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if (h > height) {
height = h;
}
}

heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

我发现这段代码解决了我在 ScrollView 中使用 SlidingTabLayout + ViewPager 时显示不正确的问题,你只需要覆盖类 ViewPager 的默认 onMeasure(int, int) 方法,然后使用重写的 MyMeasuredViewPager如下所示:

                <MyMeasuredViewPager 
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

@link http://hellsam.com/2015/01/29/Android%E7%9A%84%E5%9D%91%E4%B9%8BScrollView%E5%B5%8C%E5%A5%97ViewPager/

关于android - ScrollView 内的 TabLayout+ViewPager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39438743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com