【问题标题】:issues with coordinator layout in android ?android中的协调器布局问题?
【发布时间】:2015-12-19 10:23:48
【问题描述】:

我正在使用协调器布局来完成此视频VIDEO REQUIREMENT

现在这是我的布局:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/tabanim_maincontent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
<LinearLayout
    android:id="@+id/linearLayoutProfileImageSection"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <RelativeLayout
        android:id="@+id/relativeLayoutProfileImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ImageView
            android:id="@+id/profileImage"
            android:layout_width="110dip"
            android:layout_height="110dip"
            android:layout_alignParentTop="true"
            android:layout_centerVertical="true"
            android:adjustViewBounds="true"
            android:layout_marginTop="@dimen/profile_image_margintop"
            android:layout_marginLeft="@dimen/profile_image_marginleft"
            android:background="@drawable/llayout_bk"
            android:scaleType="centerCrop"/>

        <LinearLayout
            android:id="@+id/llayout_detail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/profile_rightside_layout_marginleft"
            android:layout_toRightOf="@+id/profileImage"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textViewUserName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="3dp"
                android:layout_marginTop="@dimen/profile_username_margintop"
                android:text="sdsdsd"
                android:textColor="@android:color/black"
                android:textSize="12sp"
                android:singleLine="false"
                android:textStyle="bold"/>

            <ImageView
                android:id="@+id/btn_follow"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/follow_btn"
                android:layout_marginTop="@dimen/profile_follow_margin_top"

                />

            <TextView
                android:id="@+id/textViewLocationProfileName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="3dp"
                android:text="sdsds"
                android:textColor="@android:color/black"
                android:textSize="15sp"
                android:layout_marginBottom="3dp"
                android:textStyle="normal" />

        </LinearLayout>
        <ImageView
            android:id="@+id/img_editprofile"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:padding="3dp"
            android:layout_marginRight="@dimen/profile_edit_margin_right"
            android:layout_marginTop="@dimen/profile_edit_margin_top"
            android:background="@drawable/edit_btn"/>
    </RelativeLayout>
</LinearLayout>

<ProgressBar
    android:id="@+id/progressbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="gone"
    />
<View
    android:id="@+id/view"
    android:layout_height="1dp"
    android:layout_width="match_parent"
    android:background="@android:color/darker_gray"
    android:layout_marginTop="@dimen/profile_tablayout_margintop"

    />


    <com.ui.MyTabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/MyCustomTabLayout"
        />

    <View
        android:layout_height="1dp"
        android:layout_width="match_parent"
        android:background="@android:color/darker_gray"
        />
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />
</LinearLayout>
    </android.support.design.widget.CoordinatorLayout>

但是我得到这种类型结果的问题 它应该以垂直顺序显示列表视图中的所有项目,而现在列表视图中有 5 个项目,但它们的长度有限且在有限的高度内我可以看到更多项目滚动如何避免?

【问题讨论】:

  • 您有什么理由不使用AppBarLayoutCollapsingToolbarLayout
  • 实际上我已经在片段中有操作栏,并且我在整个应用程序中执行相同的过程,所以我将使用操作栏,而你认为​​ CollapsingToolbarLayout 将解决我的问题
  • 我只是想知道,因为我目前正在构建一个使用折叠工具栏的应用程序,TabLayout 和一个 NestedScrollView,最终将包含一个 RecyclerViewHere is a fairly recent demo video - 如果您认为这会有所帮助,我可以发布一个答案,其中包含我用作模板的示例的链接,以及我自己的一些调整。
  • @PPartisan 可以检查一下这个演示是否可以工作,如果我在片段和片段内的操作栏中使用我将在片段和 viewpager 和选项卡中使用自定义操作栏
  • @PPartisan 请发布答案和我有布局的所有相关文件....

标签: android listview android-coordinatorlayout android-tablayout


【解决方案1】:

要实现与演示视频中发布的布局类似的布局,其中涉及折叠工具栏TabLayoutViewPager,我建议使用以下要点作为指导:

CollapsingToolbarLayout with TabLayout

如果您在加载到 ViewPager 的片段时遇到任何问题,但无法正确包装内容,那么您可以尝试以下方法:

  1. 使用这个gist by TheLittleNaruto 并用它来替换布局中的anroid.support.v4.view.ViewPager xml。此自定义 ViewPager 将包装子内容,因此非常适合 ListViewRecyclerView 内容。
  2. 或者,如果您希望 ViewPager 占用任何剩余空间而不是简单地包装内容: 在您检索 AppBarLayoutViewPagerActivity 类中,以及一个 @ 987654335@ 到您的AppBarLayout,并使用它来调整您的ViewPager 的高度,使其大小调整为占用您的AppBarLayout 下方的空间:

Activity类:

//Class variable
private int windowHeight;
//...
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int offset) {
    if (windowHeight == 0) windowHeight = getWindow().getDecorView().getHeight();
    int appBarHeight = (int) (appBarLayout.getHeight() + appBarLayout.getY());

    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mViewPager.getLayoutParams();
    params.height = (windowHeight - appBarHeight);
    mViewPager.setLayoutParams(params);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 2015-12-09
    • 2015-11-02
    • 2018-06-29
    • 1970-01-01
    • 2019-03-25
    • 1970-01-01
    相关资源
    最近更新 更多