在Android的协调布局问题? [英] issues with coordinator layout in android ?
问题描述
I M使用协调布局才达到这个视频 VIDEO需要量
i m using coordinator layout to achive this video 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个项目,但他们在有限的长度内的ADN高度有限我可以看到滚动更多的项目如何避免?
but the issue i m getting this type result it should show all items in a listview in vertical order while right now there are 5 items in listview but they are in limited length adn inside limited height i can see more items on scroll how to avoid ?
推荐答案
要实现一个类似于张贴在您的演示视频,其中涉及倒塌工具栏的布局, TabLayout
和 ViewPager
我会建议使用下面的要点作为指南:
To achieve a layout similar to the one posted in your demo video, which involves a collapsing toolbar, TabLayout
and ViewPager
I would recommend using the following gist as a guide:
CollapsingToolbarLayout与TabLayout
如果您遇到任何问题与加载到你的 ViewPager
未正确包装的内容片断,然后你可以尝试以下方法:
If you experience any issues with the fragments loaded into your ViewPager
not correctly wrapping content, then you can try the following:
- 使用此<一个href=\"https://github.com/TheLittleNaruto/SupportDesignExample/blob/master/app/src/main/java/com/thelittlenaruto/supportdesignexample/customview/WrapContentHeightViewPager.java\"相对=nofollow称号=WrapContentHeightViewPager>由TheLittleNaruto 要点,并用它在布局<$替换
anroid.support.v4.view.ViewPager
C $ C> XML 。这种习俗ViewPager
将包裹孩子的内容,所以非常适合的ListView
和RecyclerView
的内容。 - 或者,如果你会,而不是像
ViewPager
来占用任何剩余的空间,而不是简单包装内容:在活动
在这里你找回你的AppBarLayout
和ViewPager
,以及<$ C $类C> AppBarLayout.OnOffsetChangedListener 你的AppBarLayout
,并用它来调整你的高度ViewPager
所以它的大小调整占据下面的空间你的AppBarLayout
:
- Use this gist by TheLittleNaruto and use it to replace
anroid.support.v4.view.ViewPager
in your layoutxml
. This customViewPager
will wrap child contents, and so is ideal forListView
andRecyclerView
content. - Or, if you would instead like the
ViewPager
to occupy any remaining space and not simply wrap content: Inside theActivity
class where you retrieve yourAppBarLayout
andViewPager
, and anAppBarLayout.OnOffsetChangedListener
to yourAppBarLayout
, and use it to adjust the height of yourViewPager
so that its size adjusts to occupy the space below yourAppBarLayout
:
活动
类:
//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);
这篇关于在Android的协调布局问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!