画面の指定した場所にTextViewを表示したいです。
動的に作成したsurfaceViewを使用しています。
FrameLayoutをxmlに記述、指定した場所にTextViewを配置して、FrameLayoutにsurfaceViewを読み込ませたところ、Textviewごと上書きされてしまい、Textviewが表示できません。
どうしたらTextviewを表示できるでしょうか。
##activity_main.xml
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/frame"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1000" android:layout_gravity="center_vertical|right" android:id="@+id/layscore" android:textSize="50dp"/> <FrameLayout android:id="@+id/lay" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout></FrameLayout>
layにsurfaceViewを読み込ませています。
layscoreが上書きされてしまい、消えてしまいます。
javaのコードの一部も記載しておきます
##JAVA
public class MainActivity extends AppCompatActivity { private class FieldView extends SurfaceView { public FieldView(Context context) { super(context); setBackgroundColor(0xFFFFFFFF); setFocusable(true); setFocusableInTouchMode(true); requestFocus(); } } FieldView mFieldView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); set(); } void set(){ setContentView(R.layout.start); Button btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { { LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.activity_main, null, false); setContentView(view); mFieldView = new FieldView(getApplication()); FrameLayout lay = (FrameLayout) findViewById(R.id.lay); lay.addView(mFieldView); } } }); }
関連していそうな部分だけを記載しました。
##start.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="60dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="60dp" android:text="START" android:id="@+id/btn"/> </RelativeLayout> </LinearLayout>
Layoutの形を『のような形で実装できたら楽に作れそうなんですが・・・。
どうしたら指定位置にTextviewを配置できるでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/14 05:24
2016/06/14 05:27
2016/06/14 06:03
2016/06/14 06:09
2016/06/14 06:21
2016/06/14 06:26
2016/06/14 08:31