【发布时间】:2014-11-25 18:18:45
【问题描述】:
我正在尝试使用自定义布局创建 PopupWindow。这是我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="48dp" >
<ImageView
android:id="@+id/switch_iamge"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="4dp"
android:src="@drawable/switch_icon" />
<TextView
android:id="@+id/old_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/switch_iamge" />
</RelativeLayout>
我在这里创建PopupWindow:
PopupWindow popupWindow = new PopupWindow(view,
LayoutParams.WRAP_CONTENT, 48);
但是它会获得孔屏幕宽度。我还检查了this 和this,但它们没有帮助。我该怎么办?
编辑:看来问题出在ImageView。在图像中使用wrap_content 也不起作用。所以我删除了ImageView 并在TextView 中使用了drawableRight 属性,它可以工作。
【问题讨论】:
-
我认为它会因为您的图像中的 ImageView 正在显示。
-
尝试修复TextView的宽度并检查。
-
@PiyushGupta 那么问题是什么?图片仅占 32*32 平方空间。
-
@HareshChhelana 问题是我不想使用固定宽度值。
-
@MisaghEmamverdi 找到解决方案了吗?
标签: android android-layout android-popupwindow