【发布时间】:2017-03-27 19:27:18
【问题描述】:
你好! 我希望这个视图可以滚动:
如您所见,TAB1 中的“TEMP CONTENT”只是用来模拟可能出现的临时内容。
我现在要做的是让整个页面可滚动。我设法做的是使 TAB1 的内容,因此,TabLayout 的内容,可滚动,但这不是我想要做的。如上所述,应该是整个页面。
那是持有视图的 Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="at.codecrane.whosnext.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@android:color/darker_gray" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="@drawable/ic_face"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView3"
android:layout_centerHorizontal="true"
android:text="Temp Name"
android:textSize="18sp" />
</RelativeLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@color/colorPrimary">
<android.support.design.widget.TabItem
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="General" />
<android.support.design.widget.TabItem
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Statistics" />
</android.support.design.widget.TabLayout>
</android.support.v4.view.ViewPager>
</LinearLayout>
这是 ViewPager-Content 的片段布局:
<!-- TODO: Update blank fragment layout -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEMP CONTET"
android:textSize="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEMP CONTET"
android:textSize="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEMP CONTET"
android:textSize="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEMP CONTET"
android:textSize="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEMP CONTET"
android:textSize="20dp" />
</LinearLayout>
提前致谢!
【问题讨论】:
-
在你的第一个 xml 中使用滚动视图而不是线性布局作为根
-
我尝试改用滚动视图,但视图页面中根本没有显示任何内容。
标签: android android-fragments android-viewpager android-tablayout