gpt4 book ai didi

android - 如何调整屏幕大小的 ListView 项目

转载 作者:行者123 更新时间:2023-11-29 16:08:55 24 4
gpt4 key购买 nike

我制作了使用 Listview 的 App

main_acivity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/common_bg_common"
tools:context=".MainActivity" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#000000"
android:dividerHeight="3sp" >
</ListView>

</RelativeLayout>

costomItem 在下面

costomo_cell.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" >

<LinearLayout
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:background="#cc9933"
android:orientation="vertical" >

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:text="dummyCanvas"
android:textColor="#000000" />
</LinearLayout>

<LinearLayout
android:id="@+id/linear2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/linear1"
android:background="#cc3333"
android:orientation="vertical" >

<TextView
android:id="@+id/_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"/>
</LinearLayout>

</RelativeLayout>

现在,我想用一个项目填充屏幕。我想在 custom_cell.xml 中写 match_parent,但不能。

我不想写 xxdp。Linear1 是屏幕尺寸的 2/3。其他内容(linear2)是 1/3 大小...

如何配置自定义单元格布局?

--------编辑---我上传截图。黑线是一个单独的项目。我想调整屏幕尺寸 capture

最佳答案

class MyListItemView extends LinearLayout {

public MyListItemView(Context context) {
super(context);
inflate(getContext(), R.layout.costomo_cell, this);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = getResources().getDisplayMetrics().heightPixels;
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
}

现在在adapter的getView中实例化MyListItemView实例

关于android - 如何调整屏幕大小的 ListView 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15196442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com