i need to implement the leveler in view of my application , where as i have the code for the leveler provided by the google. i need to implement it in my app.
This is main.xml of bubble leveler,
<net.androgames.level.view.LevelView
android:id="#+id/level"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
how can i embed this project View in to my application view.
i think, you can simply set this view in your activity using:
setContentView(yourLevelViewObject);
OR if you want to add this view to any layout then you can use:
yourLayoutObject.addView(yourLevelViewObject);
Related
I have a library wich create a customViewGroup and do something fancy with them, by default you can use this VIEWGROUP in XML and add any child you want to it like this.
<CustomFancyViewGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cusattr="15dp"/>
<CustomFancyViewGroup/>
and this work fine except if you want to add a child programmatically .
I cannot find anyway to set "cusattr" to a view programmatically.
so is there any way to add custom Attribute to a view programmatically?
I' ve designed a xml layout-file with some standard ui-components in it. So far it works fine.
In my Java-code I've implemented a custom view which extends a SurfaceView for the purpose of animating things. Now I want to inject this custom view at runtime to the ui defined in the layout-file.
Do I have to provide for an empty view filler for that custom view in the XML?
How does this work? Can you show me a simple code snippet please ? Thanks
Use ViewGroup addView() method.
Also you can use ViewStub
You may use
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background="#color/app_bg"
android:gravity="center_horizontal">
<include layout="#layout/titlebar"/>
where, this linearLayout is in basic layout while this layout in include is another layout file. So you can even reuse this layout multiple times.
Check examples here
this way it works, but is there any more elegant way to do this, e.g. with a ViewStub ?
// the animation-view:
final LighthouseView lighthouseView = new LighthouseView(this, controller);
controller.registerView(lighthouseView);
setContentView(R.layout.activity_lighthouse);
ViewGroup container = (ViewGroup) findViewById(R.id.lighthouse_container);
container.addView(lighthouseView, 0);
setContentView(container);
I have a pretty basic custom view that consists of a 2 TextViews styled in a particular way. I'm inflating the view from the following layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
...
>
<TextView
android:id="#+id/text_line1"
tools:text="10"
.../>
<TextView
android:id="#+id/text_line2"
tools:text="Reviews"
.../>
</LinearLayout>
When I add this custom view to another layout in Android Studio via xml, the placeholder/tools text does not appear in the Android Studio preview. I'd like to see "10 Reviews" in the preview without actually setting the custom attributes which change these fields. I have imported the tools namespace in the layout containing the custom view.
Is there a way to do this? Am I creating this view incorrectly?
If I'm not mistaken, tools information is not preserved if you used the layout to inflate a custom view.
You can try using isInEditMode to populate the data using the informaion you get from AttributeSet
I have a custom View that I would like to "embed" in an WebView.
By embed I mean:
The custom view intercepts onTouch events on its area
The custom view looks like a piece of the web page, so it scrolls with the surrounding text
I wrote the custom View, so I can edit it as needed
Take a RelativeLayout or FrameLayout as Parent. then Put WebView as First Child Layout and then your CustomView as second child view.
After this put some code to show and hide the CustomView on some specific Action.
It will surly help you.
Enjoy. :)
as I said in my comment.
I can't think of a normal way to what you do. What I would do if I were you is to put the custom view in between 2 WebView objects like this:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView android:id="#+id/webView1
...
/>
<include android:layout="custom_layout" />
<WebView android:id="#+id/webView2
...
/>
</ ScrollView>
I am trying make application from this project: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.html
But here, there is a Layout that generating dynamicly. I want to create my own layout in xml file. So what should i have to do for it.
Please anyone can help me to make the xml layout from this dynamic layout ??
Thanks.
That example is not creating a "dynamic layout". The layout, which is the part you'd be defining in XML, consists of only one View object, MyView.
What I assume you are referring to by "dynamic layout" is the MyView class, which is a custom View object which accepts touch input and draws on the screen. This cannot be defined in XML... you must write the Java code to handle the logic necessary, since the regular View class (which MyView is extending) does not support such functionality.
What you would need to do is create a Java file defining the MyView class. Say for example, com.example.MyView. Then, in XML, you can include this custom view in your layout by referring to the full name, including the package name. For example...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<com.example.MyView>
android:layout_height="fill_parent"
android:layout_width="fill_parent"
</com.example.MyView>
</LinearLayout>
You can use this layout in an activity as usual using setContentView.