android– 布局问题:SliderDrawer不填充父宽度

android– 布局问题:SliderDrawer不填充父宽度,第1张

概述我在Android中使用SliderDrawer.在抽屉里面我有一个包含充气布局的布局.这是最终结果:请注意抽屉的内容(灰色)如何不占用父级的整个宽度(黑色区域).这是抽屉代码(main_layout.xml):[更新2,添加了整个代码:]<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android

我在Android中使用SlIDerDrawer.在抽屉里面我有一个包含充气布局的布局.这是最终结果:

请注意抽屉的内容(灰色)如何不占用父级的整个宽度(黑色区域).

这是抽屉代码(main_layout.xml):

[更新2,添加了整个代码:]

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  androID:layout_wIDth="fill_parent"  androID:layout_height="fill_parent">  <linearLayout androID:ID="@+ID/banner" androID:orIEntation="horizontal"    androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"    androID:gravity="center" androID:padding="3px">    <ImageVIEw androID:src="@drawable/Title"      androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" />    <TextVIEw androID:layout_wIDth="wrap_content" androID:text="@string/Title"      androID:layout_height="wrap_content" androID:textSize="18sp"      androID:gravity="center_vertical" androID:paddingleft="4px"      androID:textStyle="bold" />  </linearLayout>  <linearLayout androID:layout_below="@ID/banner" androID:ID="@+ID/mIDdle" androID:orIEntation="vertical"    androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent">    <VIEw androID:layout_wIDth="fill_parent" androID:layout_height="1dip"      androID:background="#FF555555" />    <ListVIEw androID:ID="@androID:ID/List" androID:layout_wIDth="fill_parent"      androID:layout_height="fill_parent" androID:padding="3px"      androID:layout_weight="1" />    <TextVIEw androID:ID="@androID:ID/empty" androID:layout_wIDth="fill_parent"      androID:layout_height="fill_parent" androID:text="@string/no_items"      androID:padding="3px" androID:layout_weight="1" />  </linearLayout>  <linearLayout androID:ID="@+ID/linearLayout01" androID:layout_alignParentBottom="true"    androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"    androID:orIEntation="vertical" androID:gravity="center_horizontal|bottom">    <SlIDingDrawer androID:ID="@+ID/drawer" androID:background="#22222222"       androID:layout_height="110dip" androID:handle="@+ID/handle"      androID:content="@+ID/media_player_container" androID:layout_wIDth="fill_parent">      <ImageVIEw androID:ID="@+ID/handle" androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content" androID:src="@drawable/tray" androID:scaleType="centerCrop"/>      <linearLayout androID:ID="@+ID/media_player_container"        androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"        androID:gravity="bottom|center_horizontal" />    </SlIDingDrawer>  </linearLayout></relativeLayout>

这是膨胀区域的代码(media_player_container.xml):

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"   androID:gravity="bottom|center_horizontal" androID:orIEntation="vertical"  androID:background="#FF555555" androID:padding="3px">  <Seekbar androID:ID="@+ID/progress" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:paddingBottom="3px" androID:progress="1000" />  <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"  androID:orIEntation="horizontal">    <Imagebutton androID:ID="@+ID/speakerhandset" androID:src="@drawable/handset" androID:layout_wIDth="60dip" androID:layout_height="wrap_content" androID:scaleType="center"/>    <Imagebutton androID:ID="@+ID/rewind" androID:src="@androID:drawable/ic_media_rew" androID:layout_wIDth="60dip" androID:paddingRight="3px" androID:layout_height="wrap_content" androID:scaleType="center"/>    <Imagebutton androID:ID="@+ID/play" androID:src="@androID:drawable/ic_media_play" androID:layout_wIDth="60dip" androID:paddingRight="3px" androID:layout_height="wrap_content" androID:scaleType="center"/>    <Imagebutton androID:ID="@+ID/pause" androID:src="@androID:drawable/ic_media_pause" androID:layout_wIDth="60dip" androID:paddingRight="3px" androID:layout_height="wrap_content" androID:visibility="gone"  androID:scaleType="center"/>    <Imagebutton androID:ID="@+ID/fastforward" androID:src="@androID:drawable/ic_media_ff" androID:layout_wIDth="60dip" androID:paddingRight="3px" androID:layout_height="wrap_content" androID:scaleType="center"/>  </linearLayout></linearLayout>

你能发现我做错了什么吗?

[更新1]这是代码(在onCreate()内部),我在这里扩充布局:

linearLayout container = (linearLayout) this.findVIEwByID(R.ID.media_player_container);LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);linearLayout layout = (linearLayout) layoutInflater.inflate(R.layout.media_player, null, false);container.addVIEw(layout);

解决方法:

而不是膨胀您的内容布局,然后将其添加为嵌套的线性布局,请尝试直接在media_player_container布局中包含您想要的布局.从简单开始(可能只是将其内容设置为具有坚实背景且没有填充的视图)并从那里开始工作,直到找到导致问题的原因.

您还可以考虑替换这些行:

linearLayout container = (linearLayout) this.findVIEwByID(R.ID.media_player_container);LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);linearLayout layout = (linearLayout) layoutInflater.inflate(R.layout.media_player, null, false);container.addVIEw(layout);

有:

VIEw.inflate(this, R.layout.media_player,         (VIEwGroup) findVIEwByID(R.ID.media_player_container)

通过将视图直接膨胀到容器中,您可以允许视图系统正确管理布局属性(这在技术上适用于容器,而不是您在其上定义的视图).如果没有它们,膨胀视图中定义的布局属性将在您作为子项添加之前被丢弃(因为它无法知道您将它们扩展到哪种类型的布局).

总结

以上是内存溢出为你收集整理的android – 布局问题:SliderDrawer不填充父宽度全部内容,希望文章能够帮你解决android – 布局问题:SliderDrawer不填充父宽度所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1115856.html

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

发表评论

登录后才能评论

评论列表(0条)

保存