i have some Problems with LayoutInflater and couldnt find a Solution after many hours.
I try to add a Layout in a Custom Class which extends a SurfaceView. There is no Problem when i add a Layout in the Activity. I read to inflate a Layout in a Custom Class i need the Root View (else i get a null exception). But when i use it nothing apears on the Display. Possible there is something wrong when i inflate with ViewGroup null. I tryed to inflate with root View in the Activity, but same Problem. So i do something wrong but i dont know what :( Pls Help.
Activity Class
public class Aactivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ui_main);
LayoutInflater inflater = LayoutInflater.from(this);
FrameLayout item = (FrameLayout)findViewById(R.id.ui_surface);
View child = inflater.inflate(R.layout.ui_surface, null);
item.addView(child);
}
}
Surface Class
public class Csurface extends SurfaceView{
public Csurface(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = LayoutInflater.from(context);
View root = inflater.inflate(R.layout.ui_main, null);
FrameLayout item = (FrameLayout)root.findViewById(R.id.ui_option);
View child = inflater.inflate(R.layout.ui_option, null);
item.addView(child);
}
}
ui_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/ui_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</FrameLayout>
<FrameLayout
android:id="@+id/ui_option"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</FrameLayout>
</FrameLayout>
ui_surface.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.development.Csurface
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</RelativeLayout>
ui_option.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/a_button_01" />
</RelativeLayout>
No comments:
Post a Comment