Unable to set bottom margin in Android - android

I have a ListView in an activity. In this ListView I am calling another xml file to set text properties and add an arrow image. With only TextView, I am able to set top and bottom margin of the ListView row but when I add arrow image, the bottom margin doesn't set but top margin works properly. Please let me know, where I am doing wrong. Here's my code of xml file below :
list_text_black.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:adjustViewBounds="true"
android:maxWidth="30dp"
android:maxHeight="30dp"
android:src="#drawable/arrow1" />
<TextView
android:id="#+id/list_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:text="sdfjijogbvfbghgggg"
android:textColor="#000000"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
listview_file.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" >
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="270dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:choiceMode="singleChoice"
android:layout_weight="1.32" >
</ListView>
</LinearLayout>

try this this may help you,
<?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:background="#android:color/black"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/list_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:text="Just Test"
android:textColor="#android:color/white"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:adjustViewBounds="true"
android:maxHeight="30dp"
android:maxWidth="30dp"
android:src="#drawable/arrow" />
</RelativeLayout>
</LinearLayout>

if i am getting what you want then this may help. use android:paddingBottom = "12dp" in <ImageView>..<ImageView/>

Related

Button is not displaying in layout in Android

I have made an Android activity. In this activity I have a ListView and a Button. I want to add the Button to the bottom of screen. I have tried so long but it's hidden from tabbar. My xml code is as below. Please help me.
code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.eps.blancatours.uc.Header
android:id="#+id/hdr_dest_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<RelativeLayout
android:id="#+id/rl_main_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/hdr_dest_list"
android:padding="10dp" >
<ListView
android:id="#+id/dest_List"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/btn_next" />
<Button
android:id="#+id/btn_next"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="#D41016"
android:text="#string/next"
android:textColor="#ffffff"
android:textSize="14dp" />
</RelativeLayout>
</RelativeLayout>
Make changes like below -
<?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"
tools:context=".MainActivity" >
<LinearLayout android:id="#+id/li"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<com.eps.blancatours.uc.Header
android:id="#+id/hdr_dest_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:id="#+id/list"
android:padding="30dp"
/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#68bdb6"
android:text="#string/Select" />
</RelativeLayout>
You did not close your main Relativelayout just close that layout button will appear below the listview
You didn't close your main RelativeLayout with </RelativeLayout>.
For me your code works, you just have to close your relative layout.
It does working here, all I added is just </RelativeLayout> tag before the parent tag.
and my text in place of the #String reference.
also Try changing android version when rendering layout.
Wrapping ListView and Button with nested RelativeLayout is redundant. You could set you XML like this:
<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" >
<com.eps.blancatours.uc.Header
android:id="#+id/hdr_dest_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ListView
android:id="#+id/dest_List"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/hdr_dest_list"
android:layout_above="#+id/btn_next" />
<Button
android:id="#+id/btn_next"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:background="#D41016"
android:text="#string/next"
android:textColor="#ffffff"
android:textSize="14dp" />
</RelativeLayout>
Also use match_parent instead fill_parent
Add the below inside Button
android:layout_below="#id/list"
Add android:orientation="vertical" on your both RelativeLayouts as
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.eps.blancatours.uc.Header
android:id="#+id/hdr_dest_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<RelativeLayout
android:id="#+id/rl_main_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/hdr_dest_list"
android:padding="10dp"
android:orientation="vertical" >
<ListView
android:id="#+id/dest_List"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/btn_next" />
<Button
android:id="#+id/btn_next"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="#D41016"
android:text="#string/next"
android:textColor="#ffffff"
android:textSize="14dp" />
</RelativeLayout>
</RelativeLayout>
And don't forget to clear the project.

Listview not scrolling totally android

I have a ListView that is not scrolling for complete. I inserted 20 items, but the listview is scrolling until the item 15º.
My Layout XML code here :
<?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:orientation="vertical"
android:weightSum="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="#color/sky" >
<TextView
android:id="#+id/tvQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical|center_horizontal"
android:scrollbars="none"
android:text="#string/QuoteTeste"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="14pt" />
<Space
android:id="#+id/espaco"
android:layout_width="wrap_content"
android:layout_height="30dp" >
</Space>
<TextView
android:id="#+id/tvAutor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvQuote"
android:layout_below="#+id/tvQuote"
android:layout_marginTop="22dp"
android:text="(Carlos Drummond)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/checklistview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>
</LinearLayout>
Here a screenshot:
I don't understand WHY this is happening. For example, If I put 6 items, the 6º item is not show and I can't scroll the listview. Missing something?
The problem is in your layout xml
change it with this one:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/topPart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/sky" >
<TextView
android:id="#+id/tvQuote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical|center_horizontal"
android:scrollbars="none"
android:text="#string/QuoteTeste"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="14pt" />
<Space
android:id="#+id/espaco"
android:layout_width="wrap_content"
android:layout_height="30dp" >
</Space>
<TextView
android:id="#+id/tvAutor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvQuote"
android:layout_below="#+id/tvQuote"
android:layout_marginTop="22dp"
android:text="(Carlos Drummond)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</RelativeLayout>
<ListView
android:id="#+id/checklistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/topPart" >
</ListView>
</RelativeLayout>
You should not add multiple enties below each other using android:layout_height="fill_parent" or "match_parent" (which is the same) in the same layout as you do in the LinearLayout.
Make it another RelativeLayout with using layout_below, layout_parentOnBottom and other options or place everything into one huge relative layout.
<?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:orientation="vertical"
android:weightSum="1" >
<RelativeLayout
android:id="#+id/toppart"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/sky" >
<TextView
android:id="#+id/tvQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical|center_horizontal"
android:scrollbars="none"
android:text="#string/QuoteTeste"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="14pt" />
<Space
android:id="#+id/espaco"
android:layout_width="wrap_content"
android:layout_height="30dp" >
</Space>
<TextView
android:id="#+id/tvAutor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvQuote"
android:layout_below="#+id/tvQuote"
android:layout_marginTop="22dp"
android:text="(Carlos Drummond)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/bottompart"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_below="#+id/toppart"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/checklistview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>

Alignment issues in placing the close button in dialog in android

I am trying to place the close button in the right most top corner of the dialog.However i have given the required attributes.It is not aligning properly.When viewing in the xml it is perfectly right.But it is not aligned to the right most in the emulator.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- Header Inclusion -->
<include
android:id="#+id/pheader"
layout="#layout/playheader"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginRight="1dp" >
</include>
<!-- Header Inclusion -->
<!-- Dialog Layout For Reading -->
<ScrollView
android:id="#+id/readscroller"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="55dp" >
<LinearLayout
android:id="#+id/textviewlayout"
android:layout_width="match_parent"
android:layout_height="320dp"
android:layout_centerVertical="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="40dp"
android:orientation="vertical"
android:background="#000000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.08"
android:orientation="vertical"
android:background="#6D6968">
<TextView
android:id="#+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="0.08"
android:text="Provide Overall Effectivness of the speech"
android:textStyle="bold"
android:textColor="#FFFFFF"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.70"
android:orientation="vertical"
android:background="#drawable/roundedlayout"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<TextView
android:id="#+id/readtext"
android:layout_width="match_parent"
android:layout_height="134dp"
android:layout_marginBottom="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0.70"
android:text="Comments"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<!-- Dialog Layout For Reading -->
change your relative layout from this :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
to this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
I create one playheader file as per your need as below:
playheader.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:layout_width="50dip"
android:layout_height="50dip"
android:background="#drawable/ic_launcher"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
and now my view is like this:
Try this. hope it will help.

Set 1 textview and 2 buttons independently in a Relativelayout

I have this 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="match_parent">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/upperBar"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray"
>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/txtForum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#255094"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_alignParentLeft="true"
android:maxLines="2"
android:scrollbars="vertical"
>
</TextView>
<ImageButton
android:id="#+id/btnBrowser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_alignParentRight="true"
android:src="#drawable/icon_browser"
android:contentDescription="Open Browser"
>
</ImageButton>
<Button
android:id="#+id/btnNewThread"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NewThread"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_toLeftOf="#+id/btnBrowser">
</Button>
</RelativeLayout>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:padding="10dp"
android:layout_below="#+id/upperBar">
</ListView>
</LinearLayout>
And looks like this:
The problem is that, when the TextView is too long, it overlaps the buttons. I'd like to have those elements independently that the text is long. What should I add to my code?
Thank you.
Add following code android:layout_toLeftOf="#+id/btnBrowser" for the text view.

how to reduce distance between both text in listview?

Hi I'm newly entered in this project. How to reduce listview text view distance please...
xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/thumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip">
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/thumb"
android:layout_toRightOf="#+id/thumb"
android:layout_centerVertical="true"
android:layout_marginTop="1000dip"
android:textColor="#ffffff"/>
<TextView
android:id="#+id/detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/thumb"
android:layout_alignParentBottom="true"
android:textColor="#ffffff" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imgArrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
You have given android:layout_alignParentBottom="true" to the below text.so it will set itself to the bottom of the layout.Either remove this and give marginTop to the this text or give marginTop to the above text.Here is only problem,look at it.
Use this XML as the list_item of your listview and make changes wherever needed
<?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="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaa"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bbbbbbbbbbbbbbb"/>
</LinearLayout>
</LinearLayout>
i dont know whether this is the only reqirement of yours though i have tried to shorten the distance between them.Try it n Hope this will help you.

Categories

Resources