具有layout_weights的LinearLayout以及具有不同高度的子级
我的图像按钮高度为 40 像素,但我的画廊高度要大得多。现在,我的图像按钮占据了它们所获得的整个空间,并且与我的画廊高度相同。有没有办法在保持这种水平布局的同时保持按钮的原始大小?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp" >
<ImageButton
android:id="@+id/left_arrow"
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shared_arrow_left_button_selector"
android:scaleType="fitCenter" />
<Gallery
android:id="@+id/gallery"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spacing="15dp" />
<ImageButton
android:id="@+id/right_arrow"
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shared_arrow_right_button_selector"
android:scaleType="fitCenter" />
</LinearLayout>
My image button is 40px in height, but my gallery is a lot bigger in height. Right now, my imagebuttons take up the entire space they are given, and is the same height as my gallery. Is there anway to keep the buttons their original size while keeping this horizontal layout?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp" >
<ImageButton
android:id="@+id/left_arrow"
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shared_arrow_left_button_selector"
android:scaleType="fitCenter" />
<Gallery
android:id="@+id/gallery"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spacing="15dp" />
<ImageButton
android:id="@+id/right_arrow"
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shared_arrow_right_button_selector"
android:scaleType="fitCenter" />
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在应用
两个 ImageButton,以便它们填充高度,如果您只想让 ImageButton 包裹其原始大小,只需将它们更改为
wrap_content
并删除layout_weight
属性。此外,当您将layout_weight="1"
应用于图库时,只需更改android:layout_width="0dp"
,因为宽度将由layout_weight
管理> 财产本身。你的最终布局应该是这样的,You are applying
to both the ImageButtons so they are filling the height, if you just want ImageButtons to wrap their original size just change them to
wrap_content
and remove thelayout_weight
property. Also when you are applyinglayout_weight="1"
to gallery just changeandroid:layout_width="0dp"
as the width will be managed by thelayout_weight
property itself. Your final layout should be like,删除 ImageButtons 中的布局权重 = 3,这是导致显示的图像按钮大于 Gallery 的原因。
我认为你不知道如何使用layout_weight属性,所以你不知道如何解决这个问题。首先了解layout_weight。
如果您有任何疑问,请随时问我。
在图像按钮和图库中使用下面的行,会很好。
Remove the layout weight = 3 in ImageButtons, it is the cause to show image button bigger than Gallery.
I think you don't know how to use layout_weight property, so that you don't know how to solve this problem. First know about layout_weight.
If you have any doubt feel free to ask me.
Use below lines in both image buttons and gallery, it will be nice.