android顯示文字
⑴ android在一張圖片相應位置顯示字的布局
1、在一張圖片的任意位置顯示文字,使用RelativeLayout布局,俗稱相對布局,是在Android開發中使用得最多的一種布局方式,比如在圖片的下邊欄顯示一行文字,代碼如下:
<ImageView
android:id="@+id/imageview_001"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginTop="100dp"
/>
更多Android例子,網路一下就知道了,平時也做點學習,TeachCourse比較適合初學者,謝謝採納!
⑵ Android studio怎麼給按鈕設置監聽,並讓editText顯示文字
假設你的按鈕拖拽在activity_main.xml文件裡面,你的監聽就是在Myactivity.java設置(簡單說就是你在哪個xml文件里放置了一個按鈕,就在哪個對應xml的java文件寫),而不需要新建一個class
接下來的是設置監聽
設置監聽第一步:
聲明一個Button按鍵(btn1是自己命名)
找到EditText的位置(給剛剛命名的EditText賦值)
也是在setContentView(R.layout.****);的下面輸入下面的代碼
然後在倒數第一個 } 前面輸入
String str1 = et3.getText().toString();//獲取文本框的內容並賦值給str1
String str2 = et4.getText().toString();//獲取文本框的內容並賦值給str2
String str3 = et5.getText().toString();//獲取文本框的內容並賦值給str3
str1、str2、str3是自己命名的字元串,到後面你想要用到文本框的內容就輸入str這些自己命名的String
希望能幫到你
⑶ android中怎麼將字元串顯示在textview上
1、直接寫在布局文件里,android:text="要顯示的字元串"
2、初始化要顯示字元串的textview,然後textview.settext("要顯示的字元串");
⑷ android編程如何顯示大量文本
如果是產品製作方向——
由於手機屏幕的限制,和屏幕大小的問題
顯示大量文字,在產品方面,我們一般放棄使用縮小字體類似的方法
一般的做法都是讓文本可以上下滑動來進行閱讀
如果按照上下滑動思路就很簡單了
使用ScrollView,內部嵌套一個TextView就可以了
可以來個簡單範例
============================
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="要顯示的大段文字" />
</LinearLayout>
</ScrollView>
==========================
如果是說編程界面——
如果開發使用ADT可以
在首選項中選擇常規——編輯器——文本編輯器,這里可以任意修改文字大小、顏色等
⑸ android中textview顯示文字比如: 標題:XXXX 後面的XXXX怎麼獲取
TextView是最常用的組件之一用於顯示文本
像這種需求通常是兩個TextView組成的解決方案
用兩個TextView 一個作為標題,一個作為動態內容
還是用一個TexeView 直接getText().toString() 得到文本再調用String的api split(":") 拆分,即通過:進行拆分
通常在android中都是用兩個TextVew來處理的,前面一個TextVew作為標題,是固定不變的,後面一個TextVew作為變數,動態顯示內容
獲取textView文本的api :
String txt = textView.getText().toString();
⑹ Android 如何實現豎排文字顯示
在android.graphics.Canvas類中有個沿路徑畫字的方法
void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint)
Draw the text, with origin at (x,y), using the specified paint, along the specified path.
void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint paint)
Draw the text, with origin at (x,y), using the specified paint, along the specified path.
Test.java代碼://需要在layout中定義Test,且設置背景,在java代碼中設置test Text
public class Test extends View {
private Paint paint;
private Path path;
private Matrix matrix;
private int width = -1;
private int height = -1;
private float left = 3;
private float top = 18;
private String title = "";
BitmapDrawable drawable = (BitmapDrawable) getBackground();
public Test(Context context, AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
paint.setColor(Color.WHITE);//定義字體顏色
paint.setTextSize(14);//定義字體大小
path = new Path();
path.lineTo(0,500);//定義字元路徑
matrix = new Matrix();
Log.v("onMeasure", "2");
}
@Override
protected void onDraw(Canvas canvas) {
//畫背景
Bitmap b = Bitmap.createBitmap(drawable.getBitmap(),0,0,width,height);
canvas.drawBitmap(b, matrix, paint);
//畫字
showText(canvas, title);
}
private void showText(Canvas canvas, String text){
float w;
final int len = text.length();
float py = 0 + top;
for(int i=0; i<len; i ++){
char c = text.charAt(i);
w = paint.measureText(text, i, i+1);//獲取字元寬度
StringBuffer b = new StringBuffer();
b.append(c);
if(py > 81){//定義字的范圍
return;
}
if(isChinese(c)){
py += w;
if(py > 81){
return;
}
canvas.drawText(b.toString(), left, py, paint); //中文處理方法
}else {
canvas.drawTextOnPath(b.toString(), path, py, -left-2, paint);//其他文字處理方法
py += w;
}
}
}
public void setText(String title){
this.title = title;
}
public String getText(){
return title;
}
private boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
return true;
}
return false;
}
//重寫View大小方法,使view大小為背景圖片大小
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (null != getBackground()) {
int h = drawable.getIntrinsicHeight();
int w = drawable.getIntrinsicWidth();
Log.v("onMeasure", "null != getBackground() h:" + h + " w:" + w);
width = w;
height = h;
setMeasuredDimension(w, h);
} else {
width = widthMeasureSpec;
height = heightMeasureSpec;
super.measure(widthMeasureSpec, heightMeasureSpec);
}
}
}
在Android中,若要通過程序改變屏幕顯示的方向,必須要覆蓋setRequestedOrientation()方法,而若要取得目前的屏幕方向,則需要訪問getRequestedOrientation()方法。本範例為求簡要示範更改做法,設計了一個按鈕,當單擊按鈕的同時,判斷當下的屏幕方向,例如豎排(PORTRAIT),則將其更改為橫排(LANDSCAPE);若為橫排(LANDSCAPE),則將其更改為豎排(PORTRAIT)