I have a "Tools.java" that shows "tools.xml" correct? Within this "tools.xml" RelativeLayout have a layout id = #+/contentLayout that is empty.
And I have several other activits "tool1.java", "tools2.java" ... that shows "tool1.xml", "tool2.xml" ...
How to call the class "tool1.java" for example and have it show the "tool1.xml" within the RelativeLayout that is in "tools.xml"
Thanks
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include
layout="#layout/yourxmlfilename" />
</RelativeLayout>
Related
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".view.characterlist.HaruActivity"
android:background="#drawable/harubackgound"
>
...
</RelativeLayout>
Here is a picture of the screen without ScrollView :
https://media.discordapp.net/attachments/473468257626488852/722442283181539409/unknown.png
And here with :
https://media.discordapp.net/attachments/473468257626488852/722441710067777617/unknown.png
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".view.characterlist.HaruActivity"
android:background="#drawable/harubackgound"
>
...
</RelativeLayout>
</ScrollView>
Could someone help me ? Ty
try setting the image as a background, so you would add:
android:background = "#drawable/...
in the parent relative layout.
I believe that all the textviews are going down because the image is currently in an imageview, and if you want to overlay textview over the image, then you need to set image as the background.
I want to have 3 layouts in my ScrollView but when I add them it actually doesn't scroll. I tried to put all layouts in different files, then include them, tried to put them in ListView and it doesn't work too. In this option, when I put in ScrollView the LinearLayout and there include the rest of the layouts the application show nothing. That's probably becouse I don't know how to refer to that nested layouts... This is my XML:
activity_main.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="wrap_content"
>
<ScrollView android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<include layout="#layout/first"/>
<include layout="#layout/second"/>
<include layout="#layout/third"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
#EDIT views included (all are the same so I put just one):
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</RelativeLayout>
And in the main activity I put the objects into layouts like this:
setContentView(R.layout.activity_main);
RelativeLayout first = (RelativeLayout) findViewById(R.id.first);
RelativeLayout second = (RelativeLayout) findViewById(R.id.second);
RelativeLayout third = (RelativeLayout) findViewById(R.id.third);
...some code creating views...
first.addView(myView1);
second.addView(myView2);
third.addView(myView3);
Need to put fix size in included layout, for example:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/first"
android:layout_width="match_parent"
android:layout_height="300dp"
/>
I don`t understand why do you need to add view manually when you already added it to the layout.
You should also eliminate top Linear Layout since there is no use of it.
My main xml layout file....
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relLayoutPlayerActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundimage"
android:orientation="vertical" >
</LinearLayout>
I created the viewpager.....
that layout file......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/carousel_layout_home"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:overScrollMode="never" />
</LinearLayout>
I load the images into this view pager by creating three classes & another xml file......
now I want to add this viewpager into linearlayout of main xml file....
It means I want dynamically view the viewpager in mainxml file. how to that? pls give me answer
thankyou
If you have two Layouts such as LinearLayout you can add one onto the other with addView(). In your Activity it would look something along the lines of,
LinearLayout layout = (LinearLayout) findViewById(R.id.relLayoutPlayerActivity);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout.addView(inflater.inflate(R.layout.idOfLayoutHoldingYourViewPager, null));
I have a problem with the view stub.
This is the ViewStub in my java file
ViewStub stub = (ViewStub) findViewById(R.id.stub1);
ArrayAdapter<String> content=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,files);
View inflated=stub.inflate();
ListView people=(ListView)inflated.findViewById(R.id.friends);
people.setAdapter(content);
This is the xml where I initialize the Viewstub
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id = "#+id/linear_details" >
<include layout="#layout/home_back_next_bar" />
<ViewStub android:id="#+id/stub1" android:inflatedId="#+id/showlayout"
android:layout="#layout/layout1" android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</merge>
my layout file inflated in the view stub is as follows:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/friends"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
This code gives me a NullPointerException when creating instance of the listview to fill it.
Any Ideas what causes this problem and how to solve.
Thanks alot in advance
Error in Log cat:
The reason it didnt work:
According to the docs :
http://developer.android.com/reference/android/view/ViewStub.html#inflate()
You are doing a findViewById on "The inflated layout resource" which is the very listview you are looking for.
.
Instead of using
ListView people=(ListView)inflated.findViewById(R.id.friends);
I used
ListView people=(ListView)stub.inflate();
And it worked no idea why??. but it did :))
i have a 2D game which has my custom ViewPanel which handles all the drawings (i don't have android Button elements, all my game controls are painted/handled internally).
this is my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</LinearLayout>
and this is my activity's onCreate() main code:
viewPanel = new ViewPanel(this);
setContentView(viewPanel);
from this point my ViewPanel handles all the drawings/events.
Now,
i want to integrate Ads (Mobclix), and this is how i do it:
setContentView(R.layout.mobclix_advertising_view);
Mobclix.onCreate(this);
adview_banner = (MobclixMMABannerXLAdView) findViewById(R.id.advertising_banner_view);
adview_banner.addMobclixAdViewListener(this);
adview_banner.setRefreshTime(30000);
adview_banner.getAd();
HOWEVER! it seems i can either setContentView on my ViewPanel OR on "advertising_banner_view" not both. So basically either i see my game drawing OR the advertising bar.
How can i see them both?
Try this:
my_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</FrameLayout>
Now just use my_layout as you main layout, and call addView twice on it, once with your ViewPanel and once with your AdView. You can set the gravity of the adview to float it where ever you want on the screen.
You can do this:
game.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.package.ViewPanel />
<com.package.MobclixMMABannerXLAdView />
</LinearLayout>
in your code:
setContentView(R.layout.game);
than you can use findviewbyid to get those views.