【问题标题】:View doesn't show the last +- 50dp of the content in AndroidView 不显示 Android 中最后 +- 50dp 的内容
【发布时间】:2015-12-14 19:35:53
【问题描述】:

我一直在关注使用Android Hive 的标签制作材料设计的教程。

现在我正在尝试在片段中添加 ScrollView。片段被添加到 ViewPager。但它没有显示 ScrollView 中内容的最后 +-50 dp。我认为它在 layout_height 属性中的某个地方,但我不知道如何解决这个问题。

activity_main.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.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"/>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"  />
</android.support.design.widget.CoordinatorLayout>

Fragment_one.xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/scroll"
     android:layout_height="fill_parent"
     android:layout_width="fill_parent"
     tools:context="com.a42.pthong.philips.CompanyFragment">

     <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_margin="@dimen/activity_horizontal_margin"
          android:orientation="vertical">

          <TextView
               android:text="@string/title"
               android:id="@+id/textView"
               android:textSize="20sp"
               android:textStyle="bold"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content" />
          <TextView
               android:id="@+id/content1"
               android:text="@string/content"
               android:textSize="12sp"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content" />

     </LinearLayout>

</ScrollView>

【问题讨论】:

  • 相当确定 ScrollView 内 LinearLayout 中的 android:layout_height 应该是 ="wrap_content",而不是填充父项。
  • 我试过了,但没有成功 :(.. 但是还是谢谢!

标签: android xml scrollview


【解决方案1】:

这是因为您将CoordinatorLayoutScrollView 一起使用。将您的实现更改为android.support.v4.widget.NestedScrollView 以实现正确的滚动。

CoordinatorLayout 滚动与NestedScrollingChild 的子级一起正常工作。

here 我也回答了同样的问题。

【讨论】:

  • 谢谢!现在我需要担心 ListView,但我知道我需要使用 RecycleView。
  • 甜蜜。快乐编码:)
猜你喜欢
  • 2023-02-07
  • 1970-01-01
  • 2015-12-09
  • 1970-01-01
  • 2012-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-10
相关资源
最近更新 更多