私はこのようなレイアウトを持っています
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:alignParentTop ="true"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:text="Login" />
<RelativeLayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:visibility="gone" >
<Button
android:id="@+id/btnEditUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txtLoggedInfo"
android:layout_centerInParent="true"
android:layout_marginTop="5dip"
android:text="Edit User" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
私のカスタムビューは
public class MyView extends RelativeLayout {
private Context context = null;
private TextView txtLoggedInfo;
private View contentView = null;
public MyView(Context context) {
super(context);
this.context = context;
getLayout();
}
private void getLayout() {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
contentView = layoutInflater.inflate(R.layout.main, null);
this.addView(contentView);
//......
if (bool ) {
((Button)findViewById(R.id.btnLogin)).setVisibility(View.GONE);
((RelativeLayout) findViewById(R.id.layout)).setVisibility(View.VISIBLE);
} else {
((Button)findViewById(R.id.btnLogin)).setVisibility(View.VISIBLE);
((RelativeLayout) findViewById(R.id.layout))
.setVisibility(View.GONE);
}
}
}
ログインボタンをクリックして新しいアクティビティを開始し、ログイン後にMyViewに戻りたい。
RelativeLayout.LayoutParams layputParams = new Relative.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
this.addContentView(new MyView(this), layputParams);
アクティビティ内でアクティビティに戻ります。このようにすると、ビューの可視性は変わりません。ここでの問題は何ですか。また、その問題を解決するにはどうすればよいですか。
ありがとう