我想在android的popupmenu中更改项目之间的间距
我希望有一个直接的解决方案,但是据我所知,android不会那么简单
无论如何,我也想设置弹出窗口的<?php
require 'dbh.php';
if (!isset($_GET['itemnumber'])) {
header("Location: itemdb.php");
exit();
} // no else needed -> exit()
$sql = "SELECT * FROM itemdb WHERE id = ?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: edititem.php?error=sqlerror");
exit();
} // no else needed -> exit()
$getid = $_GET['itemnumber'];
mysqli_stmt_bind_param($stmt, "i", $getid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
//Make sure an item is selected
if ($result == 0) {
$message = "You must select an item to edit!";
header("Location: edititem.php?Noresults");
exit();
} // no else needed -> exit()
while ($row = mysqli_fetch_assoc($stmt)) {
$edit_itemname = $row['name'];
$edit_itemkeywords = $row['type'];
$edit_itemego = $row['ego'];
$edit_itemweight = $row['weight'];
$edit_itemacordmg = $row['acordmg'];
$edit_itemtags = $row['tags'];
$edit_itemworn = $row['worn'];
$edit_itemaffects = $row['affects'];
$edit_itemloads = $row['loads'];
$edit_itemarea = $row['area'];
$edit_itemcomments = $row['comments'];
// does not make sense here: header("Location: edititem.php?testing");
// show your data (need to edited):
echo "Name: " + $edit_itemname + "<br/>";
echo "Area: " + $edit_itemarea + "<br/>";
echo "Comment: " + $edit_itemcomments + "<br/>";
// end of current row
echo "<hr><br/>"
}
?>
...
在这种情况下,TextView“选择奖品”将弹出窗口固定住,因此它会填充其上方的空间,但并非所有项目都适合该空间,因此android自动创建了一个草稿视图(垂直)
问题是,我知道100%的用户不会使用此滚动条,因此将永远不会看到我的菜单中“旅行”下面的项目。
如何设置高度以便为所有物品留出足够的空间?
=============更新===============
只需说明一下,这不是微调器,而是弹出菜单
maxHeight
答案 0 :(得分:2)
A
只是常规的__dict__
;它是相同的属性,但是是另一个父样式:
Base._var
这只会影响样式已分配给的>>> class Base(object):
... _var = 10
... @classmethod
... def inc_class(cls):
... cls._var += 1
...
>>> class A(Base):
... pass
...
>>> A.__dict__
mappingproxy({'__module__': '__main__', '__doc__': None})
>>> A.inc_class()
>>> A.__dict__
mappingproxy({'__module__': '__main__', '__doc__': None, '_var': 11})
。
也可以设置自定义PopupMenu
(针对单个项目,而不作为模板):
MenuItem
答案 1 :(得分:2)
您需要在styles.xml
内的AppTheme中设置首选项目行的高度:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:listPreferredItemHeightSmall">20dp</item>
</style>
您可能需要稍微修改此数字才能获得正确的值,但是它确定了这些行的高度。确保将Theme.AppCompat.Light.DarkActionBar
替换为当前使用的任何内容。
关于设置最大高度,恐怕您必须为此创建自己的扩展类,例如in this example。
答案 2 :(得分:0)
您可以为弹出菜单创建布局,并在活动中将其初始化,如下所示 XML
> <?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="match_parent"
> android:gravity="center"
> android:background="@android:color/transparent">
> <LinearLayout
> android:layout_width="wrap_content"
> android:layout_height="YOUR MAX HEIGHT"
> android:gravity="center"
> android:weightsum="YOUR NUMBER OF ITEMS"
> android:orientation="vertical"
> android:layout_gravity="center"
> >
> <TextView
> android:layout_width="wrap_content"
> android:layout_height="0dp"
> android:weight="1" /> ...no of views items
> </LinearLayout> </LinearLayout>
将其初始化为
View parentv = findViewById(R.id.activityview); //id of parent view of activity in which popup will be shown
LayoutInflater layoutInflater
= (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.YOURPOPUPMENU, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT);
TextView tv = popupView.findViewById(R.id.textviewid); //to do something with textview
tv.setText("Fashion");
popupWindow.setOutsideTouchable(true); //if you want to dismiss popup if clicked outside
popupWindow.setFocusable(true);
// Removes default background.
popupWindow.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
// popupWindow.setAnimationStyle(R.style.righttoleftstyle); can put animation to slide in popupmenu by defining any animation
popupWindow.showAtLocation(parentv, Gravity.START | Gravity.TOP,0,0);
//将在活动视图的屏幕左上角显示弹出窗口,您可以尝试对其进行一些迭代,以根据需要在屏幕上显示位置
我希望它将对您有帮助!