WindowManager和RecycleView忽略ItemList参数

时间:2016-12-08 14:13:32

标签: android layout android-recyclerview android-windowmanager

我在使用RecycleView和WindowManager(TYPE_SYSTEM_ALERT)时有一种奇怪的行为。由于某种原因,ItemList的属性(填充,宽度,高度,......)被忽略。我不知道发生了什么。我想和你们一起检查一下我是不是错过了什么或做错了什么。

在WindowManager上充气列表:

WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

paramsMap = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                PixelFormat.OPAQUE);

final RecyclerView recyclerView = new RecyclerView(getApplicationContext());

recyclerView.setAdapter(new CustomListAdapter(list));
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setPadding(0,0,0,0);
wm.addView(recyclerView, paramsMap);

项目布局:

<?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="90dp"
    android:layout_margin="15dp"
    android:background="@android:color/darker_gray">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:orientation="vertical">
        <TextView
            android:id="@+id/lincensePlace"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="aaaaaaaaaaaaaaaaaaa"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"/>
    </LinearLayout>
</LinearLayout>

它希望像那样膨胀: Correct behavior

但这就是我得到的:   Wrong behavior

0 个答案:

没有答案