Android ImageButton相对大小和位置

Android ImageButton相对大小和位置,android,Android,我正在尝试缩放ImageButton以适应50%的屏幕宽度,并将其水平居中,无论原始图像或设备屏幕大小如何。更准确地描述了我想要的最终结果 任何帮助都将不胜感激。谢谢。实现所需效果的一种方法是使用线性布局的子对象的权重属性,并结合两个不可见的视图,这两个视图将在任一侧充当25%的填充。不过,说真的,你的问题可能会好得多,下次请阅读SO发布指南 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

我正在尝试缩放
ImageButton
以适应50%的屏幕宽度,并将其水平居中,无论原始图像或设备屏幕大小如何。更准确地描述了我想要的最终结果


任何帮助都将不胜感激。谢谢。

实现所需效果的一种方法是使用
线性布局
的子对象的
权重
属性,并结合两个不可见的
视图
,这两个视图将在任一侧充当25%的填充。不过,说真的,你的问题可能会好得多,下次请阅读SO发布指南

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="20dp">


    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.25"
        android:visibility="invisible"/>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|top"
        android:layout_weight="0.5"
        android:orientation="vertical">

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.25"
        android:visibility="invisible"/>
</LinearLayout>


看到您在这个实现上的一些努力/尝试会有所帮助。很抱歉问了这么多问题,但是时间太晚了,我认为一张图片抵得上千言万语。非常感谢,这差不多就要完成了。有两件事:ImageButtons无法正确缩放图像,因此我使用了ImageView,我必须添加
android:adjustViewBounds=“true”
,以删除缩放后留下的可用空间。