簡體   English   中英

android中的協調器布局存在問題?

[英]issues with coordinator layout in android ?

我使用協調器布局來實現此視頻的視頻要求

現在這是我的布局:

<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個項目,但是它們的長度有限且內部高度有限,我可以在滾動條上看到更多的項目,如何避免?

為了實現與演示視頻中發布的布局相似的布局,其中涉及折疊工具欄, TabLayoutViewPager我建議使用以下要點作為指導:

使用TabLayout的CollapsingToolbarLayout

如果加載到ViewPager的片段無法正確包裝內容時遇到任何問題,則可以嘗試以下操作:

  1. 使用TheLittleNaruto的要點,並用它替換布局xml anroid.support.v4.view.ViewPager 此自定義ViewPager將包裝子內容,因此非常適合ListViewRecyclerView內容。
  2. 或者,如果您希望ViewPager占據所有剩余空間而不是簡單地包裝內容:Activity類中,在其中檢索AppBarLayoutViewPager ,以及AppBarLayout.OnOffsetChangedListenerAppBarLayout ,並使用它來調整您的高度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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM