我想實現在佈局的中心和底部的FrameLayout一個TextView過的圖像,因爲它是在這裏看到:疊加文本在中的FrameLayout imageview的程序 - Android電子
http://developer.android.com/resources/articles/layout-tricks-merge.html
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="@drawable/golden_gate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dip"
android:background="#AA000000"
android:textColor="#ffffffff"
android:text="Golden Gate" />
</FrameLayout>
我試圖以編程的方式實現這個,但沒有運氣..我總是得到左上角的textview ..任何人都可以幫忙嗎?這裏是我的代碼:
FrameLayout frameLay = new FrameLayout(MainScreen.this);
LayoutParams layoutParamsFrame = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
frameLay.setLayoutParams(layoutParamsFrame);
LinearLayout.LayoutParams layoutParamsImage= new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
ImageView imageView= new ImageView(MainScreen.this);
imageView.setImageResource(R.drawable.movie);
imageView.setLayoutParams(layoutParamsImage);
TextView theText=new TextView(MainScreen.this);
theText.setText("GOLDEN Gate");
theText.setTextColor(Color.WHITE);
theText.setTypeface(Typeface.DEFAULT_BOLD);
LayoutParams layoutParamsText= new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
theText.setLayoutParams(layoutParamsText);
theText.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);
frameLay.addView(theText);
frameLay.addView(imageView);
它的工作原理!非常感謝你! – andreasv
@blessenm萬分感謝 –