I'm using Eclipse ADT and I'm having a problem with a layout file. I can open it the internal xml editor, but when I open the Graphical Layout tool, it doesn't show anything, as if there was no xml file there.
This is the xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hermes.view.activities.SubTaskActivity" >
<fragment
android:id="#+id/map_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="35"
android:layout_marginBottom="15dp"
android:name="com.hermes.view.fragments.MiniMapFragment"/>
<ListView
android:id="#+id/list_subtaks"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="60" />
</LinearLayout>
Note: I wanted to show a screenshot of the Graphical Layout tool, but StackOverflow doesn't allow it for reputation stuff :/
Is this an eclipse bug or am I doing something from with the xml file. I must also say that this only happens if I put a fragment in the xml file; if I remove the fragment tag, the problem disappear, but I need to see the design with the fragment in it !.
Thanks for the help
Related
Is there a way to reuse a single activity layout-file (one orientation) for another activity with two orientations.
for example I have the MainActivity with one layout-file that just shows everything fullscreen:
activity_generic.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MergeRootFrame">
</FrameLayout>
MainActivity.java
setContentView(R.layout.activity_generic);
And then I have SettingsActivity which should show everything fullscreen in portrait-mode and everything splitscreen in landscape-mode.
activity_settings.xml
//use activity_generic.xml somehow
activity_settings.xml (land)
<?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="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false">
<FrameLayout
android:id="#+id/content_left"
android:layout_width="0dp"
android:layout_weight="40"
android:layout_height="match_parent"/>
<FrameLayout
android:id="#+id/content_right"
android:layout_width="0dp"
android:layout_weight="60"
android:layout_height="match_parent"/>
</LinearLayout>
SettingsActivity.java
setContentView(R.layout.activity_settings);
Of course there is a way to fix this problem within code by checking the orientation and inflating another layout based on that, but it feels kind of hacky. I tried to use an include tag but it didn't work. Does anybody else know the solution to this problem?
Edit
I managed to edit the activity_settings.xml so that it uses an include tag.
However it is a bit overkill because it uses almost as much code as the code from activity_generic.xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<include layout="#layout/activity_generic"/>
</LinearLayout>
At this point i'm not sure if its even possible to use activity_generic.xml instead of activity_settings.xml (portrait).
You cannot use the exact same layout and achieve the same.
However there are some built in features that android has and are a common practice.
By default android shall pick the layout files from the /res/layout folder,
for both landscape and portrait orientations.
However, you can make a /res/layout-land folder and place a layout file with the same name and make landscape related UI changes there.
Android shall automatically pick this layout file for the landscape orientation.
You can check this link for further details: Android: alternate layout xml for landscape mode
I have an android app which is marked as library and two more apps (trial version and full) which are essentially using the library and only have a package name and little bit of code in there like one has to have adverts and others don't etc.
So all (99.9%) of the code lives in library whichever app is used.
The following is the main Layout xml file of the LIBRARY APPLICATION. The adView element is also present in this file and I would like only the adview Element to be somehow in the trial app's layout without duplicating the entire layout of the library.Trial app has no layout right now it just has the libray as dependency.
How can I achieve moving the adView element code from the layout below to the relevant app who right now has no layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical" >
.... more code here
</LinearLayout>
<LinearLayout
android:id="#+id/info_window"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:orientation="horizontal">
...more code here
</LinearLayout>
</LinearLayout>
Edit: Just to add little bit more detail the app has minApi 9 and does not use support library etc
I wouldn't remove the AdView from your library XML. I would instead use code in your apps to only load and show the banner ads in the relevant app.
I'm trying to include the following layout twice:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.viewpagerindicator.TabPageIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
like the following
<include
android:id="#+id/include1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="#layout/view_pager" />
<include
android:id="#+id/include2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="#layout/view_pager" />
Actually, the second view pager does not work if I do it like that... The second view pager always stays empty... If I copy my view_pager layout and change the ids in this layout (pager to pager2 and indicator to indicator2) everything works fine. Is there a better way to do that? Copying layouts to achieve that seems to make the include useless for multiple includes of the same layout....
I'm getting the references correctly I think, but though it just does not work if I include the same layout...
pager1= (ViewPager)(findViewById(R.id.include1).findViewById(R.id.pager));
pager2= (ViewPager)(findViewById(R.id.include2).findViewById(R.id.pager));
Everything works perfectly if I copy the layout...
Edit:
I think it has to do with the FragmentManager, because the view pagers have the same id... But I don't know how to solve that correctly...
Yes it can be done. You can inflate the layout many times, but you have to make the inclusion programmatically. See the answer to same kind of question.
I'am trying to load a spinner to my layout and keep geting this error:
The following classes could not be found:
- Spinner (Change to android.widget.Spinner, Fix Build Path, Edit XML)
heres my xml:
<?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" >
<Spinner
android:id="#+id/spn_dates"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="displayDatesToSpiner" />
<ListView
android:id="#+id/LST_bought_products"
android:layout_width="match_parent"
android:layout_height="302dp" >
</ListView>
</LinearLayout>
Thanks
This sometimes happens when you rename the standard AppTheme in your android manifest. It will build and deploy just fine, but the xml design editor won't render it.
This is usually because there's an invalid attribute somewhere.
Remove the onClick and it will work.
I extended AutoCompleteTextView in android. When I use that new custom AutoCompleteTextView in my XML layout file, Eclipse shows an error saying:
You must specify a valid content view by calling setContentView() before attempting to show the popup. Exception details are logged in Window > Show View > Error Log"`.
Edited XML File is:
<?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" >
<com.mypackage.MyAutoCompleteTextView
android:id="#+id/countries_list_custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="Test">
<requestFocus />
</com.mypackage.MyAutoCompleteTextView>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
By simply taking out my custom view from the XML, the layout shows just fine.
Any help will be greatly appreciated, thanks.