I am trying to try out the tutorial online and wanted to put the tab to the layout xml. I have change the extends from Activity to TabActivity. In the design view of the layout xml, I have the below.
Error during post inflation process:
TabHost requires a TabWidget with id "android:id/tabs".
View found with id 'tabs' is 'com.android.layoutlib.bridge.MockView'
The following classes could not be found:
I have looked for solution but none of them fixed except I found one in different language. I tried using the translator on google but not so helpful.
Does anyone manage to get the tabs function.
I am using Android 2.2 Api and develop with an eclipse IDE
Known bug http://code.google.com/p/android/issues/detail?id=13092
A user suggested to switch build target to 1.6 and the issue goes away. Obviously a temporary fix.
You need a layout like this:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
See the Tab Layout tutorial for more info.
Do you have a TabWidget with id android:id/tabs as the error message tells you you need?
Switch to android Target 3.0 or 3.1. You can find that drop down list on the top right side
I had the same issue. The workaround is detailed in this link:
Comment 63 by blundell...#gmail.com, May 5, 2011
As stated above Quick Fix: Just change the API Target (top left of XML
graphical view) to 3.0 and you can see it
Related
I am developing my first Android app. Although I have 15 years of Java software development experience, Android is new to me. My desired look is a background image with other images on top of it, as well as labels and phone numbers. It seems like the best way to accomplish this is a Linear Layout for the background image, with a nested layout for the other fields on top of that. I have searched online and cannot find any sample code on how to accomplish this. Any recommendations would be greatly appreciated. Thanks in advance.
What are you using to develop? If you are you using Eclipse with the Android SDK this is super easy. Put the desired picture in the appropriate drawable folder, go to the graphical view of layout that corresponds to your activity, on the right side of the screen there is a list of all the properties, find background, then select your picture from drawables. You can also do this from the xml using android:background="#drawable/yourPic". This way you don't have to worry about having things layered on top of it.
I think you should go through followings:
1. http://phandroid.com/2011/05/11/10-tips-for-android-ui-design/
2. http://mobile.tutsplus.com/series/android-user-interface-design/
3. http://coding.smashingmagazine.com/2011/06/30/designing-for-android/
4. http://android-developers.blogspot.in/2011/09/thinking-like-web-designer.html
If I got, something like this can work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
</RelativeLayout>
<stuff>
</RelativeLayout>
I used it in an app, and made the trick.
First of all, RelativeLayout is the best layout to use. It depends on your design.
If your design says to keep all the views either vertically OR horizontally, you can use LinearLayouts in between.
My suggested way:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Horizontal">
<View1 />
<View2 />
</LinearLayout>
</LinearLayout android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Vertical"
android:layout_below="#id/layout1">
<View3 />
<View4 />
</LinearLayout>
</RelativeLayout>
Which will yield you something like this
I'm sorry if this question's been asked already but I wasn't able to find any answers. Here's some background context:
I was testing my app on my Nexus 4 to fix some minor bugs. However, just as eclipse was launching it, there was a powercut in the area, switching my computer off. Eventually, once the power restored, I thought I would set a font by .setTypeFace() before running my app again but this made my app crash when I did run it. So after fiddling around with the code and finding no fix, I decided to get rid of the whole font and just run the app with the bug fix. However, this made my app look like this.
Now on eclipse, the graphical layout is showing this. My app before today was showing like the graphical layout perfectly fine. No errors are showing up on eclipse.
Why has this happened and how do I fix this? Could I have corrupted the whole file?
Thanks.
EDIT: the xml 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:background="#drawable/testbg"
android:orientation="vertical"
android:weightSum="100" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33" >
---- bunch of textviews ----
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="57" >
---- More Textviews ----
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:orientation="horizontal"
android:weightSum="3" >
---- three buttons ----
</LinearLayout>
</LinearLayout>
I finally figured it out - it was the background. I must've obviously messed up the 9.png somewhere because it fixed itself once I got rid of the background.
Normally this happens with my apps when i change the font , some fonts appears like this in the layouts , some play around i use is adding a character or a dot after tab space , and it works , however double check the font issue again ,try to set the font again or to set another font.
Is there any way I can remove the small line that appears under tabs for android 2.1?
I have found the solution for for 2.1++ versions but couldn't find anything for android 2.1 or less.
//tabHost.getTabWidget().setStripEnabled(false); .
Can I remove this line by making tabwidget and an imageview in relative layout such that imageView overlaps this line under the tab?
only hack which i found is:
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-6dp"
android:layout_marginTop="2dp" />
Hope this helps!!
I know they changed how the constants in the resources class are stored in ADT 14 but how do I then get the id of an xml item since r.id.item gives an error now?
for example this gives me an error
mPager = (ViewPager)findViewById(R.id.pager);
this is my xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/pager"/>
</LinearLayout>
I suggest there is a different problem or you should clean your projects.
http://tools.android.com/recent/buildchangesinrevision14
Implies that the only problems you should encounter are using Id's for switches in library projects.
My personal experience is that things are fine (even in library projects, except switch)
Past some code or an error to get more help
For some reason, whenever I scroll through my list of items, the background inside my listview disappears and reappears giving rise to a "flicker" effect which I don't really want. I've tried the suggestion at: How to make a ListView transparent in Android? but it doesn't work for some reason. Any suggestions?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/screenLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#color/title_background"
android:text="#string/whatsnew_title"
>
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>
Did you include android:cacheColorHint="#00000000"? It's the most important part of the proposed fix. I've just tried your code (obviously not an exact reproduction, as you're using references to project-specific resources) with it, and it seems to work.
This post on the Android Developers blog should be of your interest.
This can also be achieved from Java (code) side: listView.setCacheColorHint(Color.TRANSPARENT);
Check your theme.xml for <item name="android:windowBackground">#null</item>. If you have it - remove it. I think one of the popular resources gives this line as example (that's how I got mine).