I have the following android layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:gravity="center"
android:orientation="vertical"
android:background="#3f5561"
android:id="#+id/MainLayout">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:layout_below="#+id/tabs" />
<com.astuetz.PagerSlidingTabStrip
android:id="#+id/tabs"
app:pstsShouldExpand="true"
app:pstsTextAllCaps="true"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#a97878"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true" />
As you can see, the ViewPager has grey color around it, which is the color of the MainLayout. My question is, how can i set the ViewPager on fullscreen(Without the MainLayout around it). For example like YouTube, PlayStore and ect. That's how i want it to look
How can i possibly do that? Example will be greatly appreciated!
You are adding left, right and top padding to the container, that's why you are getting the grey area. There is no bottom padding so bottom part is ok.
Remove these line from your RelativeLayout
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
you added padding that's why it's showing MainLayout around it, remove padding to apply ViewPager to whole screen
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
Related
I try to set my LinearLayout starts from screen edge(like Parent layout).I dont want the White Space between two layouts.
i need to start from left side from screen edge and top also edge . or follow the parent left and top properties.
NOTE:
suppose i dont want to change the Relative layout properties only changes in linear layout means how to fix it?
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.zd.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/preview"
android:focusable="true">
<requestFocus />
</LinearLayout>
</RelativeLayout>
DO LIKE BELOW.
<RelativeLayout 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"
tools:context="com.example.zd.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/preview"
android:focusable="true">
<requestFocus />
</LinearLayout>
</RelativeLayout>
remove these lines.. these are creating padding for the child.
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
But according your question.
<RelativeLayout 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:background="#color/gray"
android:clipToPadding="false" // this will do the trick here
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
// suppose you have 16dp padding
<LinearLayout
android:layout_marginTop="-16dp"
android:layout_marginBottom="-16dp"
android:layout_marginLeft="-16dp"
android:layout_marginRight="-16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="#+id/preview"
android:background="#color/green"
android:focusable="true">
<requestFocus />
</LinearLayout>
</RelativeLayout>
I'm trying to make an app with an action bar, floating button and ListView.
When I add the ListView in Android Studio it has always big margins to all sides.
Whatever I change in the layout code it doesn't help it always looks like this:
My layout code looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="appenzeller.de.glimpse.MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mainList" />
<LinearLayout
android:id="#+id/ly_bar_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="right"
android:orientation="horizontal">
<android.support.design.widget.FloatingActionButton
android:id="#+id/button_addc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="28dp"
android:src="#drawable/ic_add_white_18dp"
android:onClick="addNewEntry"
app:borderWidth="0dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp" />
</LinearLayout>
</RelativeLayout>
What am I doing wrong?
Try to remove
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
from your RelativeLayout. You said "all sides", I can only see left/right. But if it's all sides you also have to remove "paddingTop" and "paddingBottom".
Your relative layout is using padding which means you are leaving some space from sides.
Removing the following lines will remove padding
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
if you want to remove padding from top and bottom as well you can remove following tag as well
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
I'm new to Android have this problem making a scrollview that is supposed to scroll over a ListView of 10+ items.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.naqishop.naqi.MainActivity"
tools:showIn="#layout/activity_main">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView"
android:entries="#array/options" />
</ScrollView>
</LinearLayout>
The problem is that I can not extend scroll views to show more that one item at a time. I tried to tamper with layout_height of the scrollview (like assigning the value to 500dp)
Also I tried adding
android:fillViewport="true"
as suggestd here
but it did not change the height. So appreciate your hints.
This is because you've set android:layout_height="wrap_content". Replace that with
android:layout_height="match_parent" and it'll take up the whole height.
I have seen the answer of this question but none of them work for me. In android I have an extra gap between the margin and toolbar so it is not looking like a actionbar. How to remove that gap?activity_main image
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#FF7043"
android:elevation="4dp"
android:layout_height="?actionBarSize"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
android:id="#+id/tool_bar">
</android.support.v7.widget.Toolbar>
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#00E676"
tools:context="com.example.partha.customtitlebar.MainActivity">
<include
android:id="#+id/tool_bar"
layout="#layout/toolbar"
></include>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/textView"
android:layout_below="#+id/tool_bar"
android:layout_alignParentStart="true"
android:layout_marginTop="55dp" />
</RelativeLayout>
If you look closely, you'll notice that you've applied padding for all four sides on the Toolbar's parent, i.e, the RelativeLayout
Removing the following lines will fix it:
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
This is because of the padding you have added to the parent RelativeLayout ViewGroup.
you have two options
it's either you set the padding to 0dp but you will lose padding for the entire screen
or you nest the the TextView inside another ViewGroup like LinearLayout and apply the padding to that LinearLayout rather than the RelativeLayout. with this you get the padding for your entire content while still making sure there is no padding around the Toolbar which will make it fit the screen like the deprecated ActionBar.
This examples illustrate how you can achieve the second option
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00E676"
tools:context="com.example.partha.customtitlebar.MainActivity">
<include
android:id="#+id/tool_bar"
layout="#layout/toolbar">
</include>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/tool_bar"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/textView"
android:layout_below="#+id/tool_bar"
android:layout_alignParentStart="true"
android:layout_marginTop="55dp" />
</LinearLayout>
</RelativeLayout>
I have an xml file which contains two RelativeLayouts. The trouble is that the second Relativelayout does not go up to the display limit. It looks like a border around the layout.
How can I display the second layer also on the border of the display?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:background="#color/colorAccent"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="newservice"
tools:showIn="#layout/activity_newservice">
<RelativeLayout
android:id="#+id/test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark"
android:layout_alignBottom="#+id/viewmap"
android:layout_centerHorizontal="true">
</RelativeLayout>
</RelativeLayout>
Remove this line on the top layout:
android:paddingTop="#dimen/activity_vertical_margin"
You are putting a padding on the top, so the second layout will not fill the first like you want.
Regards!
Remove your
android:paddingXXX from parent RelatvieLayout
that is making issue
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:background="#color/colorAccent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="newservice"
tools:showIn="#layout/activity_newservice">
<RelativeLayout
android:id="#+id/test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark"
android:layout_alignBottom="#+id/viewmap"
android:layout_centerHorizontal="true">
</RelativeLayout>
</RelativeLayout>
Try this