Remove space between app border and a List view - android

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>

Related

How to set my Child Layout also starts from parent's position?

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>

Android studio layout background error

<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/background"
tools:context="com.example.black.myfirstproject.MainActivity">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
android:background="#drawable/background"
i wanted background in MainActivity so added background and clicked "Run"
-> app is down
why my app is down?
// before added background.png in res ->drawable folder
You should use an ImageView - Caution: there are serious memory implications if large images aren't loaded correctly.
You should also read: Displaying Bitmaps Effectively
<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.black.myfirstproject.MainActivity">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/background"/>
</RelativeLayout>
Also refer to:
android:scaleType=""
for options on positioning the image and specifying how it is displayed within the ImageView.

Android SearchView not positioning correctly

I downloaded some sample code here https://trinitytuts.com/get-contact-list-and-show-in-custom-listview-android/ which searches and lists contacts in my phone. The resulting app builds and loads well. I believe it uses the Android search widget as at the top of my mainactivity I have :
import android.widget.SearchView
(However I do not have a searachable.xml file which I have seen in some sources
is a feature of this Search Widget)
According to Google, I believe the searchview widget can be
positioned anywhere in the activity (I don't want it at the top
of the activity, I want it at the bottom):
http://developer.android.com/guide/topics/search/search-dialog.html#TheBasics
According to Google in the link above the the search dialogue always appears at the top of an activity, however I am lead to believe the widget can be positioned in different places.
But when I try to change the position of the Searchview in my activity, it doesn't display.
For example, this works fine in my activity_main xml, the searchview is at the top of the page:
<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="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<SearchView
android:background="#5b74a8"
android:queryHint="howdy"
android:padding="8dp"
android:id="#+id/searchView"
android:drawableLeft="#android:drawable/ic_menu_search"
android:layout_width="match_parent"
android:singleLine="true"
android:layout_gravity="right"
android:layout_height="wrap_content"></SearchView>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contacts_list"></ListView>
</LinearLayout>
But in this case the SearchView isn't visible at all. Any ideas how I can place my search widget at the bottom?
<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"
tools:context=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contacts_list"></ListView>
<SearchView
android:background="#5b74a8"
android:queryHint="howdy"
android:padding="8dp"
android:id="#+id/searchView"
android:drawableLeft="#android:drawable/ic_menu_search"
android:layout_width="match_parent"
android:singleLine="true"
android:layout_gravity="right"
android:layout_height="wrap_content"></SearchView>
</LinearLayout>
Your list view is hiding SearchView..
You can do following to see its going at the end
<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.codepath.mytestapp.MainActivity">
<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="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<ListView
android:id="#+id/contacts_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="right"
android:background="#5b74a8"
android:drawableLeft="#android:drawable/ic_menu_search"
android:padding="8dp"
android:queryHint="howdy"
android:singleLine="true"
/>
</RelativeLayout>

Textview not skipping to next line android

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>

How to generate background images?

I have the layout like below -
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:scrollbars="vertical"
tools:context="com.example.MainActivity$FragmentRegister" >
...
and the following image - (download link).
How should I generate valid backgrounds from this image? What should be their sizes? Should I generate separate images for landscape mode? Should I use 9-patches somehow there?
Use ImageView with ScaleType property.
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/background"
android:scaleType="fitXY"
/>

Categories

Resources