【发布时间】:2015-12-27 18:01:34
【问题描述】:
我希望有和活动来显示一些统计数据。在这个活动中,我想输入开始和结束日期,并用它们显示一些统计数据和一些图形。为此,我创建了一个活动,其中我选择输入日期的顶部(如果已修复)。然后我有一个 TablLayout 和一个 viewpager,我在其中显示统计数据和图形。 所有这些似乎都可以正常工作,这是result on the activity。但是,我的问题是双重的: 一方面,我无法自动调整 viewpager 的大小以适应活动高度并正确显示片段的内容。如果我将 viewpager 设置为 wrap_content 并将片段设置为 match_parent,则不会显示任何内容。但是,如果我手动强制 viewpager 高度,那么我可以看到 viewpager 工作(但不能正确调整活动高度)。 另一方面,当我能够看到 viewpager 内容时,我只想滚动 viewpager 的内容。但是,如果我插入一个滚动视图或一个嵌套滚动视图,整个活动就会滚动,这是我不想要的。 这是我想将所有这些放在一起的活动布局:
<?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:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.app.asaak.activities.InformesActivity"
tools:showIn="@layout/activity_informes">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp"
>
<!-- ================ LAYOUT BOTONES ================ -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
>
<!-- ================ BOTON DESDE ================ -->
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/informes_boton_desde"
android:text="DESDE"
android:layout_weight="1"
/>
<!-- ================ BOTON HASTA ================ -->
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/informes_boton_hasta"
android:text="HASTA"
android:layout_weight="1"
/>
</LinearLayout>
<!-- ================ LAYOUT TEXT ================ -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:weightSum="2"
>
<!-- ================ TEXTVIEW DESDE ================ -->
<com.app.asaak.textViews.CTextViewName
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="dd/mm/aaaa"
android:id="@+id/informes_text_desde"
android:textSize="20sp"
android:textAlignment="center"
/>
<!-- ================ TEXTVIEW HASTA ================ -->
<com.app.asaak.textViews.CTextViewName
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="dd/mm/aaaa"
android:id="@+id/informes_text_hasta"
android:textSize="20sp"
android:textAlignment="center"
/>
</LinearLayout>
<!-- VIEWPAGER -->
<android.support.design.widget.TabLayout
android:id="@+id/tabs_informes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<!-- VIEWPAGER -->
<android.support.v4.view.ViewPager
android:id="@+id/pager_informes"
android:layout_width="match_parent"
android:layout_height="1000dp"
android:layout_below="@id/tabs_informes"
/>
</LinearLayout>
</RelativeLayout>
这是我想放在标签通知或标签图形上的两个内容的示例。
标签图形:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<!-- GRAPHICS AND INFORMATION HERE THAT DOESN'T FIT THE ACTIVITY SO MUST BE SCROLLED -->
</LinearLayout>
你可以看到 viewpager 的高度是强制的,如果我放 wrap_content 我什么都看不到。
我该怎么做?谢谢!!
【问题讨论】:
标签: android android-layout android-viewpager android-tablayout