我使用相对布局在XML中制作了我的图像按钮。当我制作它们时它们看起来不错,但是当我在手机上运行时它会变小!我希望它扩展到我的设备的宽度(或任何设备的宽度)
这是我的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/prewedbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/weddingbutton"
android:layout_alignParentTop="true"
android:layout_marginTop="90dp"
android:contentDescription="@drawable/prewedbutton"
android:src="@drawable/prewedbutton" />
<ImageButton
android:id="@+id/weddingbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="103dp"
android:contentDescription="@drawable/weddingbutton"
android:src="@drawable/weddingbutton" />
</RelativeLayout>
这是我的Java:
package com.example.ijazphotography;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.content.Intent;
public class PhotographyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photography);
// Show the Up button in the action bar.
ImageButton prewed = (ImageButton) findViewById(R.id.prewedbutton);
prewed.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), PreWedActivity.class);
startActivityForResult(intent, 0);
}
});
ImageButton wed = (ImageButton) findViewById(R.id.weddingbutton);
wed.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), Wedding.class);
startActivityForResult(intent, 0);
}
});
}
}
答案 0 :(得分:1)
尝试使用android:layout_width="fill_parent"
和android:scaleType="fitXY"
,并告诉我您的结果。
答案 1 :(得分:0)
更改android:layout_width =&#34; wrap_content&#34;到android:layout_width =&#34; match_parent&#34;它应该扩展到设备宽度。
答案 2 :(得分:0)
如果您希望按钮占据父宽度,则可以将按钮的宽度更改为fill_parent
android:layout_width="fill_parent"
答案 3 :(得分:0)
尝试以下代码
<ImageButton
android:id="@+id/prewedbutton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/weddingbutton"
android:layout_alignParentTop="true"
android:layout_marginTop="90dp"
android:contentDescription="@drawable/prewedbutton"
android:src="@drawable/prewedbutton" />
<ImageButton
android:id="@id/weddingbutton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="103dp"
android:contentDescription="@drawable/weddingbutton"
android:src="@drawable/weddingbutton" />