【问题标题】:How to manage Whatsapp Scroll View Logic (Android)如何管理 Whatsapp 滚动视图逻辑 (Android)
【发布时间】:2016-06-27 11:58:18
【问题描述】:

我尝试在滚动视图中创建带有滚动视图的布局 Whatssupp 的工作原理 这是我的布局的样子

当我向上滚动时,“第一部分”应该消失,“第二部分”及其 lisview 应该占据第一位置,但主题应该保持在屏幕顶部。非常熟悉 Whatssupp。我发现的例子并不能解决我的问题。希望能得到任何帮助。谢谢。

这是我的 xml 代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <!-- Main Container -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <!--Following  Followers Part 1 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btn_leftside_layout_2_followers"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:text="554 Followers" />

            <ImageView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:src="@drawable/person_icon" />

            <Button
                android:id="@+id/btn_leftside_layout_2_following"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:text="654 Following" />

        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.7"
            android:gravity="center"
            android:text="@string/txt_frag_followers_following"
            android:textSize="35dp" />
        <!--TOPICS Part 2 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="4"
            android:background="@color/grey_200"
            android:orientation="vertical">

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some Button" />


            <ListView
                android:id="@+id/lv_leftside_layout_2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </ListView>

        </LinearLayout>

    </LinearLayout>


</LinearLayout>

【问题讨论】:

    标签: xml android-layout android-studio layout


    【解决方案1】:

    您所遵循的 xml 样式不适合将来使用。因为都是固定/静态视图元素 你可以试试下面的代码

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
    
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
    
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar1"
                    android:layout_width="match_parent"
                    android:layout_height="80dip"
                    android:gravity="top"
                    android:minHeight="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:titleTextAppearance="@style/AppTheme.Toolbar.Title"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    >
    
                </android.support.v7.widget.Toolbar>
    
                <android.support.design.widget.TabLayout
                    android:paddingTop="5dip"
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_gravity="bottom"
                    app:tabMode="scrollable"
                    app:tabGravity="center"
                    app:tabIndicatorHeight="4dip"
                    app:tabTextAppearance="@style/NavigationTabTextAppeareance"
                    app:tabIndicatorColor="@color/white" />
    
    
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:background="@color/semiwhite"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
    
    
    </android.support.design.widget.CoordinatorLayout>
    

    对于视图寻呼机适配器,您可以设置任何您想要的数据

    【讨论】:

    • 感谢您的建议,我不习惯您推荐的结构,但应用的第二部分将改进这种结构,我们只需要主机。
    • 好的,然后尝试将android:layout_height="0dp" android:layout_weight="1" 用于第一部分和第二部分,并在 onScroll 中隐藏第一部分
    • 我是否需要使用一些滚动视图,我希望从答案中收到此信息建议
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    • 1970-01-01
    • 2014-08-17
    • 2019-01-02
    • 1970-01-01
    相关资源
    最近更新 更多