【发布时间】:2015-12-07 01:20:00
【问题描述】:
我有一个CoordinatorLayout 用于显示AppBarLayout。但是,问题是我的RelativeLayout 和LinearLayout 被我的ListView 隐藏了。此外,我的ListView 没有完全显示:相反,第一个ListView 元素的一部分被切断了,但我可以滚动查看其余部分。以下是我的尝试:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
xmlns:fresco="http://schemas.android.com/tools"
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>
<RelativeLayout
android:layout_below="@id/comments_coordinator_layout"
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"
/>
<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>
<ListView
android:id="@+id/lv_comments_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/send_message"
android:layout_below="@id/view_post">
</ListView>
<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" >
<EditText
android:id="@+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:hint="Comment back!"
android:inputType="textMultiLine"
android:background="@color/white"
android:scrollHorizontally="false" />
<Button
android:id="@+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
我不明白的一点是,为什么当我单击布局的design 选项卡时,我的所有布局似乎都相互重叠,而不是显示在彼此下方。此外,我不明白为什么ListView 优先于我的LinearLayout 和RelativeLayout 显示。有什么办法可以让我从上到下具有以下结构:AppBarLayout -> RelativeLayout -> ListView -> LinearLayout。任何帮助,将不胜感激。谢谢!
如果这意味着什么,在我的 AndroidManifest 中,我有 android:windowSoftInputMode="stateVisible"
块引用
编辑:这是我想要实现的一个例子
编辑:在听取了小太阳的一些建议后,这是我目前所得到的:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
xmlns:fresco="http://schemas.android.com/tools"
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>
<RelativeLayout
android:layout_marginTop="?attr/actionBarSize"
android:layout_below="@id/comments_coordinator_layout"
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"
/>
<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">
<ListView
android:layout_marginTop="225dp"
android:id="@+id/lv_comments_feed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/send_message">
</ListView>
<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" >
<EditText
android:id="@+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:hint="Comment back!"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="@+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
编辑:EditText 的问题。如您所见,当我单击EditText 时,布局仅显示ListView,并隐藏包括ActionToolBar 和Status Bar 在内的所有内容。
编辑:显示 Android 清单
<activity android:name=".com.tabs.activity.Comments"
android:label="View Post"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".com.tabs.activity.news_feed"/>
</activity>
编辑:Tiny Sunlight 的建议:
<FrameLayout>
<ToolBar></ToolBar>
<Relative Layout as List header></RelativeLayout as ListHeader>
<ListView></ListView>
<LinearLayout for Edit Text></LinearLayout for EditText>
</FrameLayout>
【问题讨论】:
-
请上传你想要实现的图片。
-
添加了我想要的图片!
-
只需添加 marginTop = RelativeLayout's height 和 marginBotton = LinearLayout' height 和 ListView's height 应该设置为 match_parent 。如果您不需要动画,请删除 CoordinatorLayout AppBarLayout 并将所有视图包含在 RelativeLayout 中。您是否需要像向上滚动 Listview 时那样的动画,RelativeLayout'height 变为零?
-
@tinysunlight 我不需要动画,但我只是想知道,如何在没有协调器布局的情况下实现我在上图中发布的工具栏外观?我认为这是我能做到的唯一方法。
-
我添加了一个答案。 Toolbar 只是一个 View 。它与 Coordinator Layout 无关。
标签: android android-layout listview android-listview android-coordinatorlayout