I am using ViewPager with PagerTabStrip:
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"/>
</android.support.v4.view.ViewPager>
And I would like to accomplish my tabs to look like this as Google recommends:
I have two tabs and I would like for each of them to be fixed and take 50% of the screen. I was looking through the options in XML and programmatically and can't find anything useful.
How can I accomplish that? Thank you.
I'm not sure about android.support.v4.view.PagerTabStrip. But you can use alternative library for getting this effect, i use it in my one project and it works well. After you add the lib to your project, set pstsShouldExpand to true
You should use android.support.design.widget.TabLayout instead of PagerTabStrip.
Related
I do have a toolbar right now, but I don't really understand a lot of the things that I needed to add and copypaste from tutorials and other questions to get it to work. Also, my toolbar doesn't display an elevation even though I set android:elevation to 9dp.
Similar to the Google I/O app, I've set up a resource in /layout for my toolbar. I copied the name and named it "toolbar_actionbar_with_headerbar". Please excuse that it doesn't make any sense.
This is the content:
toolbar_actionbar_with_headerbar.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="128dp">
<Toolbar
android:id="#+id/toolbar"
android:elevation="9dp"
android:layout_height="128dp"
android:layout_width="match_parent"
android:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
android:gravity="bottom" />
</LinearLayout>
Now, as it's apparently supposed to be done, I am applying my toolbar to activities by including them in their /layout XML-file. Works fine.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
[...]
<include layout="#layout/toolbar_actionbar_with_headerbar" />
[...]
</RelativeLayout>
However, this is my first question. When I did that initially, my toolbar was cut off at the sides like all other content of the activity, according to the margins set at the beginning of the xml. Right now, I simply deleted those, and add margins for every text field and other things on the activity. There probably is a better way?
The second question is: Why doesn't my elevation work? I've even tried setting it through code onCreate, but that doesn't work either. And lastly, what would I have to do to properly support devices pre-Level21?
Thanks a lot.
You should read this post: appcompat-v21
Take care when you copy some code text, there are some ” that are wrong, and you should change to ".
About elevation (you can read it in the post too), it only works with lollipop.
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
So i use SlidingMenu library with a FragmentActivity in my app.
There is a GoogleMap in the layout and a menu on the left side with some content.
When i pull the menu to see it, there is a big black rectangle there, covering my sliding menu content. After i click it once, it is disapearing.
Can anybody has something to say about this?
I had the same issue on android 2.3.7 but not in 3.x or later versions. After rotating the view the menu renders fine after.
I found a solution using a custom TransparentSupportMapFragment from: Android MapView With Sliding Menu Obscures Menu
Fragment Black screen issue
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
<!-- hack to fix ugly black artefact with maps v2 -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
</FrameLayout>
This is a known problem.
You may want to have a look at these issues:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4639
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4659
Maybe you can find a workaround in comments there.
I know this question is too old but since I come here by chance and see there is no accpeted answer I will answer this.Hope it help someone someday.
My solution is add a light layout (about 1dp) with transparent background above the "Shopradar" layout of yours. This worked for me,hope it works for you too ;)
I m still new to android and working on my first application. so far so good. among others the app will contain a ViewPager to switch between different xml layouts through swiping. this works nice.
however I would like to use the ViewPagerIndicator to indicate the position of the displayed template.
so i tried to include the code based on different tutorials/ instructions to my project but the templates/ ViewPager wont show anymore, the app breaks at that point. Thanks for any hints in advance ;)
here is the code + logCat
And in the xml you have:
<com.viewpagerindicator.TabPageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
But you are using UnderlinePageIndicator in your code, so it should be:
<com.viewpagerindicator.UnderlinePageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
If it's not a typo, your missing a paranthesis in this line:
UnderlinePageIndicator indicator = UnderlinePageIndicator)findViewById(R.id.indicator);
should be
UnderlinePageIndicator indicator = (UnderlinePageIndicator)findViewById(R.id.indicator);
i want to make application in android Tablets like in ipad which have spliting screen,
How i can do that ? if any body have idea please send me!
Thank you in advance.
This is achievable using the Fragments API. Fragments are available since Android 3.0, but there's also a Support Library that lets you use these API's from Android 1.6. Hope this helps.
Using fragments: check http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/
it's a tutorial with sample application that uses the compatibility package (allows you to support from API 4), it may help
this is not a 'feature' limited to iOS
you can easily do this in Android by using two vertical LinearLayouts and assigning them equal weight - to split the screen into half or Different weights to achieve something like the image you provided.
And of course, there are a lot of other ways to do that.
This will be the fragment xml file. then you have to write two xml files for CustomerList(Left Part) and CustomerInfo(Right Part). your activity should extends FragmentActivity. try with this:::
<fragment class="ui.misc.Customers$CustomerList"
android:id="#+id/customerlistfragmant" android:layout_weight="1"
android:layout_width="550px"
android:layout_height="wrap_content"
/>
<fragment class="ui.misc.Customers$CustomerInfo"
android:id="#+id/customerinfofragmant" android:layout_weight="1"
android:layout_width="350px" android:layout_height="wrap_content" />
<FrameLayout android:id="#+id/regscreentwo" android:layout_weight="1"
android:layout_width="0px"
android:layout_height="fill_parent"
/>
</LinearLayout>
you can use the APIs described here: Fragments API