android ImageButton layout_width layout_height match_parent 无效

我在设置 layout_width layout_height 设置成match_parent 切换到视图的时候 自动变成b 0dp。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="myapp.truncate.example.com.demo1.MainActivity"
    android:orientation="vertical"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_name"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="0dp" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="0dp" />

</android.support.constraint.ConstraintLayout>
阅读 2.8k
2 个回答

贴出代码,不然看不出。。

首先我不明白你描述了些什么
但从你贴出的代码可以看出你根节点使用的是ConstraintLayout 这个布局适合场景在拖拽开发,也就是可视化开发。
你可以试试新建一个布局xml,然后在里面做你想做的事情
当然你可以直接将ConstraintLayout 改为其他 比如 LinearLayout

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题