[英]Nested Scroll View in Coordinator Layout not working?
I want to have a NestedScrollView
in my CoordinatorLayout
but the scrolling just never works. 我想在我的
CoordinatorLayout
有一个NestedScrollView
,但滚动永远无法进行。 I don't see what I'm doing wrong here. 我看不到我在做什么错。 Is there an issue with the
NestedScrollView
being inside the CoordinatorLayout
? NestedScrollView
位于CoordinatorLayout
内部是否存在问题? Could someone tell me why my layout isn't scrollable? 有人可以告诉我为什么我的布局不可滚动吗? Here was my attempt:
这是我的尝试:
comments.xml: comments.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:flatui="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fresco="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
android:id="@+id/comments_coordinator_layout">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/comments_appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_marginTop="?attr/actionBarSize"
android:id="@+id/view_post"
android:layout_width="match_parent"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:layout_height="175dp"
android:background="#e6e6e6">
<com.facebook.drawee.view.SimpleDraweeView
android:layout_marginTop="15dp"
android:id="@+id/poster_picture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
fresco:placeholderImage="@mipmap/blank_prof_pic"
fresco:roundedCornerRadius="5dp"
fresco:roundAsCircle="true"
/>
<TextView
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="@id/poster_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:id="@+id/poster_name"/>
<TextView
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:layout_toRightOf="@id/poster_name"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:id="@+id/post_date"/>
<TextView
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/poster_picture"
android:layout_below="@id/poster_name"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/view_status" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:id="@+id/container_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/send_message">
</LinearLayout>
<LinearLayout
android:id="@+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<com.cengalabs.flatui.views.FlatEditText
android:id="@+id/write_comment"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="5"
android:paddingLeft="10dp"
android:gravity="bottom|left"
android:cursorVisible="false"
android:hint="Comment back!"
android:inputType="textMultiLine"
flatui:fl_fieldStyle="fl_box"
android:scrollHorizontally="false" />
<com.cengalabs.flatui.views.FlatButton
android:id="@+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
flatui:theme="@array/sea"
flatui:fl_textAppearance="fl_light"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
EDIT: Adding in screen shot and layout initialization: 编辑:添加屏幕快照和布局初始化:
AndroidManifest.xml: AndroidManifest.xml中:
<activity android:name=".com.tabs.activity.Comments"
android:label="View Post"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="keyboardHidden"
android:windowSoftInputMode="adjustResize|stateVisible|stateAlwaysHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".com.tabs.activity.news_feed"/>
</activity>
The reason why I need to have my Layout scrollable is because of this piece of code in Comments.java. 我之所以需要使Layout可滚动的原因是因为Comments.java中的这段代码。 This looks in my database and dynamically adds views into the
containerList
layout I have described in comments.xml. 这会在我的数据库中查找,并将视图动态添加到我在comment.xml中描述的
containerList
布局中。 Comments.java: Comments.java:
public void populateComments(long postId) {
//Prepare layout inflater and container
//This is for populating the container container_list
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout containerItems = (LinearLayout) findViewById(R.id.container_list); // this replaces your listview
for (Comment i : commentsDatasource.getCommentsForPost(postId)) {
View childView = vi.inflate(R.layout.comment_item, null);
TextView message = (TextView)childView.findViewById(R.id.comment_message);
TextView name = (TextView) childView.findViewById(R.id.commenter_name);
TextView timestamp = (TextView) childView.findViewById(R.id.comment_timestamp);
message.setText(i.getComment());
name.setText(i.getCommenter());
timestamp.setText(i.getTimeStamp());
//Set profile picture
DraweeController controller = news_feed.getImage(i.getCommenterUserId());
SimpleDraweeView draweeView = (SimpleDraweeView) childView.findViewById(R.id.commenter_profile_photo);
draweeView.setController(controller);
containerItems.addView(childView);
}
}
Screenshot of what is happening: You can't see it but my keyboard covers my LinearLayout
called container_list
. 发生的情况的屏幕截图:您看不到它,但是我的键盘覆盖了我的
LinearLayout
名为container_list
。
Edit: Added screenshot when I added in getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
编辑:当我添加到
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
时,添加了屏幕截图getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
in my Activity
在我的
Activity
您尚未在Toolbar
设置任何滚动标记,请尝试将其添加到布局中的Toolbar
:
app:layout_scrollFlags="scroll|enterAlways"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.