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"
Related
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 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
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"
I'm developing an android app which uses a list view using android studio.But when i use it a space is being displayed between list view and app borders.how can i remove that space?? Like in this pic I need my app to be designed .The following code is XML code for listview i got in my editor.Suggest the changes for space removal.
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
The padding is due to the padding provided to RelativeLayout
From your XML code remove padding by making you code look like
<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=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
I am a complete beginner in android programming, and I am working with TextViews. I want two TextViews with one on top and one on bottom. But it doesn't work, and I am not sure why. Here is the xml
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:text="#string/hello_world"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
So I have the first TextView as fill_parent for width to skip a line, but instead it just takes it out. I can't add a picture as a I just made this account for this question, but it just displays the first TextView and not the next. What is the mistake I made?
In a LinearLayout, you need to set the orientation.
android:orientation="vertical"
Use this code, here orientation was missing in your code
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:text="#string/hello_world"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>