android-在LinearLayout中将layout_weight与ImageView一起使用

android-在LinearLayout中将layout_weight与ImageView一起使用,第1张

概述我试图将ImageView放置在屏幕中间,目的是在其上方和下方放置其他视图,因此我决定使用LinearLayout(垂直)和LinearLayout(水平).但是,当我将layout_weight用于ImageView时,图像完全消失(显示空白屏幕).ImageView的图像在onCreate()中设置.我希望ImageView占据屏幕宽度的50%,因此我要

我试图将ImageVIEw放置在屏幕中间,目的是在其上方和下方放置其他视图,因此我决定使用linearLayout(垂直)和linearLayout(水平).但是,当我将layout_weight用于ImageVIEw时,图像完全消失(显示空白屏幕). ImageVIEw的图像在onCreate()中设置.我希望ImageVIEw占据屏幕宽度的50%,因此我要使用权重.

@H_404_4@<?xml version="1.0" enCoding="utf-8"?><linearLayoutxmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="match_parent"androID:layout_height="match_parent" androID:orIEntation="vertical"><VIEw androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_weight="1"/><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent" androID:orIEntation="horizontal"androID:layout_weight="2"><VIEw androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_weight="1"/> <ImageVIEw androID:layout_weight="2" androID:layout_height="wrap_content" androID:layout_wIDth="wrap_content" androID:ID="@+ID/albumartImageVIEw"></ImageVIEw> <VIEw androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_weight="1"/></linearLayout><VIEw androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_weight="1"/></linearLayout>

解决方法:

为了使layout_weight对任何东西都有用,需要有剩余的空间.您在linearLayout顶部下方的第一个视图具有layout_height =“ fill_parent”.那占据了整个房间.尝试在您希望由layout_weight确定尺寸的任何地方设置layout_height =“ 0dp”,我认为您的结果会更好.

总结

以上是内存溢出为你收集整理的android-在LinearLayout中将layout_weight与ImageView一起使用全部内容,希望文章能够帮你解决android-在LinearLayout中将layout_weight与ImageView一起使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1083379.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存