Android ImageButton是否在onCreateView()期间将高度与宽度匹配?

Android ImageButton是否在onCreateView()期间将高度与宽度匹配?,android,android-layout,android-imagebutton,Android,Android Layout,Android Imagebutton,请帮助我,如何将高度与宽度对齐。我什么都试过了,没用。 编辑:添加完整布局 创建按钮的代码如下所示 LinearLayout showLayout = (LinearLayout) view.findViewById(R.id.show_full_btn); showButton = new ImageButton(activityContext); <LinearLayout android:id="@+id/top_layout"

请帮助我,如何将高度与宽度对齐。我什么都试过了,没用。 编辑:添加完整布局

创建按钮的代码如下所示

LinearLayout showLayout = (LinearLayout) view.findViewById(R.id.show_full_btn);
showButton = new ImageButton(activityContext);

<LinearLayout
                android:id="@+id/top_layout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.3"
                android:orientation="horizontal">

                <LinearLayout
                    android:id="@+id/count"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.1"
                    android:orientation="vertical">
                </LinearLayout>

                <TextView
                    android:id="@+id/w_tv"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.8"
                    android:typeface="normal"/>

                <LinearLayout
                    android:id="@+id/show_full_btn"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.1"
                    android:scaleType="fitXY"
                    android:orientation="horizontal">
                </LinearLayout>
            </LinearLayout>
LinearLayout showLayout=(LinearLayout)view.findviewbyd(R.id.show\u full\u btn);
showButton=新图像按钮(activityContext);

谢谢。

您正在将
android:scaleType
交给一个不适用的
线性布局,它与ImageButton一起工作,因此将您的视图声明为
ImageButton
并将
scalyType
应用到它,或者如果您有点拘泥于布局,只需:

尝试使用内部带有ImageView和LinearLayout的FrameLayout。对于 例如,尝试更改图像的alpha并将其移动到前景 在FrameLayout中,因此LinearLayout保持在背景上


您将
android:scaleType
赋予一个不适用的
LinearLayout
,它与ImageButton一起工作,因此将您的视图声明为
ImageButton
,并将
scalyType
应用于它,或者如果您有点拘泥于布局,只需:

尝试使用内部带有ImageView和LinearLayout的FrameLayout。对于 例如,尝试更改图像的alpha并将其移动到前景 在FrameLayout中,因此LinearLayout保持在背景上


如果您发现很难从XML布局中获得结果,那么请尝试在活动的onCreate方法中进行。您可以很容易地完成它。

如果您发现很难从XML布局中获得结果,请尝试在活动的onCreate方法中完成。您可以很容易地完成它。

您在问题中谈论的是一个
ImageButton
,但在XML中没有使用
ImageButton
,只是
LinearLayout
。另外,在java中,
showLayout
showButton
是两个独立的变量,没有连接。

您在问题中提到的是
ImageButton
,但在XML中没有使用
ImageButton
,只是
LinearLayout
。另外,在java中,
showLayout
showButton
是两个独立的变量,没有连接。

您到底想要什么?宽度和高度相等?是的,图像宽度是布局的宽度,使高度与宽度相同。该图片未拉伸。请发布完整的XMLposted完整布局您到底想要什么?宽度和高度相等?是的,图像宽度是布局的宽度,使高度与宽度相同。该图片未拉伸。请将完整的XMLposted完整布局I打包的ImageButton发布到LinearLayout中,但ImageButton的scaleType不起作用。结果是一样的。如果希望图像填充整个线性布局,只需将图像按钮
宽度
高度
设置为
匹配父对象
。我将图像按钮打包为线性布局,但ImageButton的scaleType不起作用。结果是一样的。如果希望图像填充整个线性布局,只需将图像按钮
宽度
高度
设置为
匹配父项
。我已根据代码创建了ImageButton,但它也不起作用。我根据代码创建了ImageButton,但它也不起作用。