【问题标题】:Hiding View in Fragment on Scroll of Other View在其他视图滚动的片段中隐藏视图
【发布时间】:2017-04-05 16:37:41
【问题描述】:

我在 content_main 中使用导航抽屉活动,其中有一个线性布局,它将随片段膨胀。

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_home"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="net.techdesire.khabargujarat.HomeActivity"
    tools:showIn="@layout/app_bar_home">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fragment_container"/>

</RelativeLayout>

fragment_home.xml

<android.support.percent.PercentRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="fragment.HomeFragment">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            app:layout_heightPercent="40%"/>


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="5dp"
            app:layout_heightPercent="60%"
            android:layout_below="@+id/viewpager">

            <TextView
                android:id="@+id/about"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/about_khijadiya"
                android:textAppearance="@style/TextAppearance.AppCompat.Large"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/about"
                android:text="@string/dummy"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"/>
        </RelativeLayout>
</android.support.percent.PercentRelativeLayout>

我在名为 about 的 textview 中有大量内容。我想让它可滚动,就像在图像中一样。首先将 relativelayout 滚动到全屏,如果 about 的内容仍然溢出,则仅使 about textview 可滚动。当滚动到顶部时,如果用户从那里向下滑动,则重新显示 viewpager。

【问题讨论】:

  • 我不明白你想要什么。你能试着用另一种方式解释吗?

标签: android android-layout android-fragments


【解决方案1】:

我认为,您的要求是在滚动时折叠视图。

所以你可以使用 “android.support.design.widget.CollapsingToolbarLayout”。

它在材料设计中实现。

你可以参考这个链接: http://www.androidhive.info/2016/05/android-working-with-card-view-and-recycler-view/

【讨论】:

  • 是的,它是这样的,但不完全是这样。我不想操作工具栏和其他东西。我可以只更改一个xml文件吗?
  • 是的,但这取决于你的观点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多