android - 对话占据整个屏幕
问题描述
我正在创建一个带有数字选择器和按钮的对话,但不幸的是它占据了整个屏幕。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<NumberPicker
android:id="@+id/numberPicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:descendantFocusability="blocksDescendants"
android:layout_marginTop="64dp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/numberPicker1"
android:text="Set" />
</RelativeLayout>
这是我创建对话的方式
final Dialog d = new Dialog(CreateShiftActivity.this, R.style.Theme_AppCompat);
d.setTitle("NumberPicker");
d.setContentView(R.layout.num_dialog);
解决方案
尝试包装您的相对布局:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
我建议以后使用约束布局。
希望能帮助到你。
编辑
试试这个约束:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<NumberPicker
android:id="@+id/numberPicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="8dp"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/numberPicker1"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp"
android:layout_marginStart="8dp" android:layout_marginEnd="8dp"/>
</android.support.constraint.ConstraintLayout>
推荐阅读
- java - 在运行时进程中执行“启动”
- sql-server - 存储过程中的 IF ELSE 条件以包含或排除周末数据
- postgresql - Escape \n when exporting CSV using COPY command
- r - 在 R 中跨多个列标记不同的组合
- angular - 单击按钮时从传单地图中删除多边形
- javascript - 在javascript中链接多个异步函数
- android - Google Play 游戏服务,SHA1 公版要添加哪个密钥?
- sql - 分区表 SQL 的别名
- android - 深层链接意图返回未解析的引用
- html - 如何在 HTML 中嵌套对象名字