i am referring this to implement 3 level expandable list. the code works fine. but my problem is , the items in the child elements not filled the whole area. because of that i cant expand the next child element by clicking on it.(i have to click the exact area which is child element text appeared)
can someone point me, where is the issue?
i have edit my xml view also as android:layout_width="fill_parent"
but didn't worked..
please help me on this.
thank you.
EDIT
HERE THE ALL LAYOUT XML CODES.
ROOT
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff5b5b"
android:orientation="vertical" >
<TextView
android:id="#+id/itemRootTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
</LinearLayout>
PARENT
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#40e0d0"
android:orientation="vertical" >
<TextView
android:id="#+id/itemParentTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
</LinearLayout>
CHILD
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#839096"
android:orientation="vertical" >
<TextView
android:id="#+id/itemChildTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
</LinearLayout>
MAIN XML LAYOUT
<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="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=".MainActivity" >
<ExpandableListView
android:id="#+id/expList"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
>
</ExpandableListView>
</RelativeLayout>
I also encountered this problem with a spinner
I solved it like this
child xml.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#839096"
android:orientation="vertical" >
<TextView
android:id="#+id/itemChildTitle"
android:layout_width="match_parent" <== and this
android:minWidth="500dp" <=== add this
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
</LinearLayout>
Related
Hey I'm making a simple chat application. I'm having these two layouts to pass for the inflater to add to the RecyclerView:
received_msg.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f00">
<TextView
android:text="Hello"
android:textColor="#fff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
sent_msg.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fff"
android:layout_gravity="right">
<TextView
android:text="Text"
android:textColor="#f00"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
RecyclerView:
<android.support.v7.widget.RecyclerView
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical" />
The layout_gravity property seem to have no effect on the sent_msg.xml's LinearLayout. What to do?
You can make the two item XML's full width (match_parent) and move the layout_gravity and background attributes to the child TextView:
sent_msg.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" (* Changed)
android:layout_height="wrap_content">
<TextView
android:text="Text"
android:background="#fff" (* Changed)
android:textColor="#f00"
android:layout_gravity="right" (* Changed)
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
in my app I am encountering this problem:
As you can see i added the option to let the use specify a name through an edit text in an alertDialog. Hypotetically the user could enter an extremely long name, ruining the entire layout as the following rows will overlap.
How can I enter a specified height and width for each row?
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:longClickable="true"
/>
grid_item.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout for a single list item -->
<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:gravity="center_vertical"
android:orientation="horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
android:padding="16dp">
<TextView
android:id="#+id/text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="test text"
/>
</LinearLayout>
Give some height to your row item parent or textview as below:
<?xml version="1.0" encoding="utf-8"?>
<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="100dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
android:padding="16dp">
<TextView
android:id="#+id/text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="test text"
/>
</LinearLayout>
Or setheight of your textview or give it maxlines
<?xml version="1.0" encoding="utf-8"?>
<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:gravity="center_vertical"
android:orientation="horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
android:padding="16dp">
<TextView
android:id="#+id/text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="6"
android:minLines="6"
tools:text="test text"
/>
</LinearLayout>
I have two ListViews: listview and listview1. listview contains 7-8 columns and the last column contain an EditText. I want to show two ListViews with no spaces and they should be filled.
Here is my code:
XML
<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=".ShowTwoListView">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:weightSum="1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#+id/lvFoods"
android:background="#000000"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5" />
<ListView
android:id="#+id/lvRestaurants"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"/>
</LinearLayout>
</RelativeLayout>
Items
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ivFoods"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
This is my result:
Your sub view needs to match its parents width
<?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="wrap_content">
<ImageView
android:id="#+id/ivFoods"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Currently my ListView is exactly below my TextView. How can I make the ListView at the center of the screen while my TextView maintain its position on top?
Below is my layout:
<?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:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/hp_color"
tools:context=".MainActivity" >
<TextView
android:id="#+id/cityText"
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/condDescr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/cityText" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/condDescr"
android:orientation="vertical" >
<ListView
android:id="#+id/mainListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
</LinearLayout>
</RelativeLayout>
You can use Gravity to place the listview in center of the screen.
<?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:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/hp_color"
tools:context=".MainActivity" >
<TextView
android:id="#+id/cityText"
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/condDescr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/cityText" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/condDescr"
**android:gravity="center_vertical|center_horizontal"**
android:orientation="vertical" >
<ListView
android:id="#+id/mainListView"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
</LinearLayout>
</RelativeLayout>
Try setting
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
And although I'm no expert here, it's my impression that there's little point to having a ListView in a LinearLayout. Both are scrollable (which isn't advised) and there's not much point if LinearLayout only has one child.
I know how to make an expandedlistview, but I don't know what should i use to see the arrow down and up , how please ?
like when i open a group the arrow becomes down and when i close it , the arrow becomes up
Main 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" >
<ExpandableListView
android:id="#+id/ExpList"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:groupIndicator="#null" />
</LinearLayout>
Group 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="55dip"
android:background="#FF0000"
android:orientation="vertical" >
<TextView
android:id="#+id/tvGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:textColor="#000000"
android:textSize="17dip" />
</LinearLayout>
child xml
<?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="55dip"
android:background="#FF0000"
android:orientation="vertical" >
<TextView
android:id="#+id/tvChild"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="17dip" />
</LinearLayout>
remove this line from your xml code android:groupIndicator="#null"