android - 仅滚动 ListView 并将 LinearLayout 标题留在顶部
问题描述
我有一个设计,其中有一小部分屏幕专门用于显示用户的个人资料图像。下面,由分隔符分隔的是 ListView 中包含的项目列表。我希望当我滚动列表时,配置文件的顶部视图将保留在那里并且不可滚动,因此只有列表是可滚动的:
目前有一个 ListView 膨胀onCreate
,然后header.xml
添加一个包含顶部图像的图像,如下所示:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.word_list);
ListView listView = (ListView) findViewById(R.id.list);
listView.addHeaderView(getLayoutInflater().inflate(R.layout.header, null));
这是word_list.xml
:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="true"
android:orientation="vertical" />
这是 header.xml:
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/headerImageView"
android:layout_width="match_parent"
android:layout_height="119dp"
app:srcCompat="@drawable/profile_image" />
<View
android:id="@+id/headerDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider" />
这就是我想要实现的目标:
解决方案
your view will look like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:id="@+id/register_container"
android:paddingRight="16dp"
android:background="#FFF">
<ImageView
android:id="@+id/headerImageView"
android:layout_width="match_parent"
android:layout_height="0"
android:layout_weight="1"
app:srcCompat="@drawable/profile_image"/>
<View
android:id="@+id/headerDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
android:layout_marginBottom="4dp"/>
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:id="@+id/list"/>
</LinearLayout>
推荐阅读
- apache-kafka - 当我在某个阈值之后不再想接收数据时使用哪个 Kafka 生产者属性?
- graphql - 如何使用 apollo-server 进行缓存
- .net-core - 针对 .Net Framework 与 .Net Core 的 Web API
- linux - 在linux中用sed替换空格
- sql - 如何为记录添加权重以查找最匹配的结果
- dockerfile - dockerfile 中的 apt-get update 会破坏应用程序的一致性?
- excel - ADODB Recordset:关闭对象时不允许操作
- sonarqube - 我如何知道哪条规则对 sonarqube web api 有效或无效?
- reactjs - material-ui createMuiTheme 调色板类型深色不会将文本颜色更改为浅色
- python - 根据正在运行的测试用例切换装饰器的顺序?