cuốn sách gpt4 ai đã làm

java - 在窗口管理器中膨胀类时出错

In lại Tác giả: Walker 123 更新时间:2023-11-29 02:26:03 25 4
mua khóa gpt4 Nike

mã số

public class FloatingWindow extends Service{
WindowManager wm;
LinearLayout ll;
LayoutInflater li;

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
View myview;
li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_INPUT_METHOD |
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
params = new WindowManager.LayoutParams(
500, 1000, WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.CENTER | Gravity.CENTER;
myview = li.inflate(R.layout.service_floating_window, null); // your layout here
wm.addView(myview, params);

XML



android:layout_width="match_parent"
android:background="@color/black"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">


<>
android:background="@drawable/allusers"
android:layout_below="@id/actionBar"
android:layout_width="match_parent"
android:layout_height="match_parent">

<>
android:id="@+id/top"
android:padding="2dp"
android:paddingStart="20dp"
android:paddingEnd="10dp"
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">

<>
android:background="@null"
android:src="@drawable/close"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="match_parent" />



<>
android:paddingVertical="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">


<>
android:text="Name"
android:layout_centerVertical="true"
android:id="@+id/name"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"/>

<>
android:text="Online"
android:layout_centerVertical="true"
android:id="@+id/online"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"/>









<>
android:layout_above="@+id/linearlayout"
android:scrollbars="vertical"
android:id="@+id/message_list"
android:padding="2dp"
android:background="@drawable/allusers"
android:layout_below="@+id/top"
android:layout_width="match_parent"
android:layout_height="match_parent">

<>
android:background="@null"
android:padding="1dp"
android:layout_alignParentBottom="true"
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="50dp">

<>
android:scaleType="center"
android:src="@drawable/add_image"
android:id="@+id/add_image"
android:layout_width="50dp"
android:background="@null"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />

<>

android:layout_marginVertical="5dp"
android:layout_toRightOf="@id/add_image"
android:id="@+id/midleft"
android:layout_width="0.5px"
android:layout_height="match_parent"
android:background="@color/white"/>

<>
android:paddingVertical="5dp"
android:paddingHorizontal="10dp"
android:textColorHint="@color/white"
android:hint="Write a message..."
android:id="@+id/input_message"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_toEndOf="@+id/add_image"
android:layout_toStartOf="@+id/send_message" />

<>
android:layout_marginVertical="5dp"
android:layout_toLeftOf="@id/send_message"
android:id="@+id/midright"
android:layout_width="0.5px"
android:layout_height="match_parent"
android:background="@color/white"/>


<>
android:scaleType="center"
android:background="@null"
android:src="@drawable/send_button"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="@+id/send_message"
android:layout_width="50dp"
android:layout_height="match_parent"
android:text="Send" />

<>
android:layout_marginHorizontal="10dp"
android:layout_alignParentBottom="true"
android:id="@+id/bottomline"
android:layout_width="match_parent"
android:layout_height="0.5px"
android:background="@color/white"/>




nhập mô tả hình ảnh ở đây

每当我尝试调出 float 窗口时,我都会收到此异常...我也是窗口管理器的新手,所以不确定是什么导致了问题...我了解到的一件事是 xml 文件不能有应用栏.. .但我的没有,但仍然显示错误...有人可以帮我吗......

câu trả lời hay nhất

好的,问题就在这里

android:layout_height="?attr/actionBarSize"

我真的不得不“评论”每一行以查看问题出在哪里,因为其他任何地方都没有问题

我将高度设置为 50dp,现在工作正常

关于java - 在窗口管理器中膨胀类时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52145248/

25 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress