結論
【解決したい課題】AndroidでFrameLayoutの上にボタンを重ねると、ボタンが半透明になってしまい超見難いのをどうにかしたい。
【解決方法】アプリのスタイルを見直せばよい。
詳細
FrameLayoutにSurfaceViewを作ってそこに画像を描くアプリを作っていた。
操作用のボタンを設置しようとして、ググったところFrameLayoutを使って重ね合わせるのが定石だということでやってみた。
わかりやすくするため、肝の部分だけソースコードを書くとこんな感じ。
activity_main.xml その1:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000000" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ボタンですよ" />
</LinearLayout>
</FrameLayout>
</RelativeLayout>
MainActivity.java その1:
package com.example.test1;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
このアプリの画面は次の通り。ボタンが半透明になっていることがわかるだろうか。
