两个控件布局,占满父亲

qq758610209 2016-01-05 10:59:33
我的mainactivity的布局文件,默认的是一个相对布局。我里面就两个控件,一个Button和一个ImageView。我想让Button紧贴着父亲的上面,ImageView占满剩下的区域。Button的高度就普通的就行。我贴上我的代码,老出错。一运行就崩掉。

<Button
android:id="@+id/mybtn"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="点我"/>

<ImageView
android:id="@+id/image_view"
android:layout_below="@id/mybtn"
android:layout_marginBottom="0dp"
android:scaleType="centerInside"
/>
...全文
285 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
UESTC少尉 2016-01-05
  • 打赏
  • 举报
回复
1楼说的可以的,你可以试试
AImmortaI 2016-01-05
  • 打赏
  • 举报
回复
改成这样: <ImageView android:id="@+id/image_view" android:layout_below="@id/mybtn" android:layout_marginBottom="0dp" android:scaleType="centerInside" android:layout_width="match_parent" android:layout_height="match_parent" />
sagittarius1988 2016-01-05
  • 打赏
  • 举报
回复
因为没指定width和height

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button 
                 android:id="@+id/mybtn"
                 android:layout_alignParentTop="true"         
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:text="点我"/> 
     
        <ImageView
                 android:id="@+id/image_view"  
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:layout_below="@id/mybtn"
                 android:scaleType="centerInside" />
</RelativeLayout>
大崔527 2016-01-05
  • 打赏
  • 举报
回复
ImageView 没有宽高的 兄弟。 1L正解。

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧