安卓开发

ListView中inflate出来的item的parent设置

2019-08-23  本文已影响2人  手指乐
<?xml version="1.0" encoding="utf-8"?>
<TextView android:layout_width="match_parent"
    android:layout_height="200dp"
    android:text="abc"
    xmlns:android="http://schemas.android.com/apk/res/android" />

这时200dp不起作用,而是根据里面的文字大小来决定item的高度,比如如下起作用:

<TextView android:layout_width="match_parent"
    android:layout_height="200dp"
    android:text="abc"
    android:textSize="200dp"
    xmlns:android="http://schemas.android.com/apk/res/android" />
<?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="300dp">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:text="abc"/>
</RelativeLayout>
<?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="300dp">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="abc"/>

 </RelativeLayout>
<?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">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="abc"/>

</RelativeLayout>

以下高度变成了200dp:

<?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">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="abc"/>

</RelativeLayout>
上一篇下一篇

猜你喜欢

热点阅读