Set 1 textview and 2 buttons independently in a Relativelayout - android

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.

Related

Unable to set bottom margin in 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/>

Why the TextView in XML layout is not appearing

The problem is with the textview which has the id editTextLabelID as shown below in the code.
I am trying to have a layout designed as follows: label:editText
What I have in the xml layout is, a Relativelayout with green background. And inside it, there is a textview which should be my label and next to it horizontally, there should be an edittext
the problem is, according to the below code, I receive the the below result shown in the image. And the edittext, although it precedes the textview in the xml layout, however it shadows it. how to place both of the textview and edittext horizontally right after each other?
UPDATED
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/titleBackGroundColor">
<RelativeLayout
android:id="#+id/RelativeLayout00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal">
<TextView
android:id="#+id/addLocationActivityTitleID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/titlesTextSize"
android:text="#string/addLocationActivityTitle"
android:textColor="#color/titleColor">
</TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginTop"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor">
</TextView>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="text">
</EditText>
</RelativeLayout>
</LinearLayout>
UPDATED
Results:
Try This :
<?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">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginTop"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor">
</TextView>
<EditText
android:id="#+id/editTextID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
</RelativeLayout>
you are missing these 3 lines in your edit text
android:layout_width="match_parent"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_alignParentTop="true"
if you don't put it to match parent, it will be very small
the ems value is not a good use here usually
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginTop"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor">
</TextView>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_alignParentTop="true"
android:inputType="text">
</EditText>
</RelativeLayout>
</LinearLayout>
// try this way,hope this will help you...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/addLocationActivityTitleID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/titlesTextSize"
android:text="#string/addLocationActivityTitle"
android:textColor="#color/titleColor"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor"/>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:ems="10"
android:inputType="text"/>
</LinearLayout>
</LinearLayout>
in your code, you have many non-usefull layouts, simply you can do it like this :
<TextView
android:id="#+id/addLocationActivityTitleID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/titlesTextSize"
android:text="#string/addLocationActivityTitle"
android:textColor="#color/titleColor"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ff00">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/labelsTextSizes"
android:layout_alignParentLeft="true"
android:layout_marginLeft="4dp"
android:textColor="#color/contentsColor"/>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_marginLeft="4dp"
android:layout_alignTop="#+id/editTextLabelID"
android:layout_alignBottom="#+id/editTextLabelID"
android:layout_width="match_parent"
android:ems="10"
android:inputType="text"/>
</RelativeLayout>

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.

Can we place two textviews in footer xml file in android?

I am displaying a header and footer for a listview. Here I am displaying all the data dynamically. Now I want to keep a title to my footer...So I tried to keep another textview in my footer.xml file. But it is not accepting. How can I place a title for my footer data?
My Code:
<?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" >
<TextView
android:id="#+id/exptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#000000"
android:textSize="12dip" >
</TextView>
</LinearLayout>
Help me regarding this...Thanks in Advance
Try this
using two layout one is using the textview and other is using the listview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome"
android:textColor="#ffffff"
android:layout_gravity="center_horizontal" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome"
android:textColor="#ffffff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
Another XML:
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
Do I get you right? You want to place a TextView above and one below a ListView?
Than you have to do it like this:
<?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" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="TextView" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="TextView" />
The Important part ist the layout_weight attributes.
Try this
you can us two xml one is set the two textview and other xml used the listview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome"
android:textColor="#ffffff"
android:layout_gravity="center_horizontal" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome"
android:textColor="#ffffff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
Another XML:
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>

Android widgets layout setup

In my app i have a custom dialog whose layout is like the following:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"
android:scrollbars = "vertical"
android:scrollbarAlwaysDrawVerticalTrack = "true"
android:padding="10dp" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" >
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="blablabla...."/>
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:src="#drawable/book1"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" >
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="blablablablablablablablabla..."/>
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:src="#drawable/book2"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
That is, i show a list of two horizontally placed widgets: a TextView showing some text and an, adjacent to the text, an ImageView widget showing an image.
What i would like to do is to show the ImageView widgets in such a way that they are aligned, that is, the image 1 start at the same column of image 2.
How can i do that?
Thx!
I'm not exactly sure what you are hoping for, but I would do the following:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="blablabla...." />
<ImageView
android:id="#+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:src="#drawable/book1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/image1"
android:text="blablablablablablablablabla..." />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_below="#+id/image1"
android:layout_alignParentRight="true"
android:src="#drawable/book2" />
</RelativeLayout>
</ScrollView>
I changed it to a relative layout and used some attributes such as android:layout_below
and android:layout_alignParentRight="true to get these changes. I hope this helps.

Categories

Resources