[英]Android Button text changes to vertical after clicking button
在我的应用程序中,我有一个按钮,单击时将新图像加载到图像视图中。 问题在于,当它执行此操作时,按钮上的文本会改变方向。
继承我这堂课的代码
package com.michaelpeerman.demotivational_posters;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class ImageGallery extends Activity {
public ImageView i;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_gallery);
Button next = (Button) findViewById(R.id.next);
Button download = (Button) findViewById(R.id.download);
download.setOnClickListener(this.buttonhandler);
next.setOnClickListener(this.buttonhandler);
try {
int rand = 1 + new Random().nextInt(2368);
String url = "http://someurl.com/"+rand+".jpg";
i = (ImageView)findViewById(R.id.imageView);
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());
i.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
View.OnClickListener buttonhandler = new View.OnClickListener()
{
public void onClick(View v)
{
switch (v.getId())
{
case R.id.next:
loadImage();
break;
}
}
};
void loadImage(){
int rand = 1 + new Random().nextInt(2368);
String url = "http://someurl.com/"+rand+".jpg";
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());
i.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
当应用程序首次使用第一个按钮加载时,文本很好。 但是当我点击下一步时按钮上的文字会改变。
这也是布局
<?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" >
<TableLayout
android:id="@+id/tablelayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableRow android:id="@+id/tableRow1"
android:layout_height="wrap_content">
<Button android:id="@+id/download"
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight=".45"
android:text="Download"/>
<Button android:id="@+id/next"
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_weight=".45"
android:text="Next"/>
</TableRow>
</TableLayout>
<TableRow android:id="@+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@id/tablelayout1">
<ImageView android:id="@+id/imageView" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
</RelativeLayout>
这是问题的图片
试试这个修改。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/dwnld"
android:text="Download"
android:layout_margin="2dp"
android:textColor="#000000"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="30dp"/>
<Button
android:id="@+id/next"
android:text="Next"
android:layout_margin="2dp"
android:textColor="#000000"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="30dp"/>
</LinearLayout>
<ImageView android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.