Android extendablelistveiw child element in foreground - android

I'm not sure that extendable list is the best solution for this but this is the only thing that came to my mind.
Here is my problem:
I want to create a list and when I click on an element one (or maybe there'll be multiple) element'll appear and push down the other elements that are below it. This is how the extendable list works, but here comes my problem I want that the child element are in front of the group elements and I have no idea how could I do it.
Here it is a picture maybe you can understand it better:
As Gavriel requested:
main:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.example.lalala.listview.MainActivity">
<ExpandableListView
android:id="#+id/extd_list"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
group:
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:background="#000000">
<TextView
android:id="#+id/left_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_widthPercent="75%"
android:textSize="17dp"
android:textColor="#f9f93d" />
<TextView
android:id="#+id/right_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_widthPercent="25%"
android:layout_toRightOf="#+id/left_text"
android:textSize="17dp"
android:textColor="#f9f93d" />
</android.support.percent.PercentRelativeLayout>
expanded child:
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" >
<TextView
android:id="#+id/extended_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="20dp"
android:paddingBottom="20dp" />
</android.support.percent.PercentRelativeLayout>

What i did in a similar situation was to copy the ExpandableListView's layout xml into my project, and modify it according to my needs, and create MyExpandableListView extends ExpandableListView that uses my version of the layout and doesn't change anything else. I hope this helps.

Related

tools:listheader doesn't work although tools:listitem does

I have a fragment layout that contains the following code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".BlankFragment">
<ListView
android:id="#+id/blankList"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listheader="#layout/menu_header"
tools:listitem="#layout/fragment_item" />
</FrameLayout>
My fragment_item contains the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal"
android:background="#f0f0f0">
<ImageView
android:id="#+id/image_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:paddingBottom="3dp"/>
<TextView
android:id="#+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/menu_article_text_size"
android:layout_marginStart="16dp"
android:textAppearance="?attr/textAppearanceListItem" />
</LinearLayout>
My menu_header contains the following code:
<?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"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="12dp"
android:id="#+id/view2"
app:cardCornerRadius="40dp"
android:layout_centerHorizontal="true">
<ImageView
android:layout_height="80dp"
android:layout_width="match_parent"
android:id="#+id/imageView1"
android:src="#drawable/ic_launcher_background"
android:scaleType="centerCrop"/>
</android.support.v7.widget.CardView>
</LinearLayout>
My problem is that for some reason when I run it the app the fragment works, the list appears and the items of it are fine, but the header simply isn't there.
any help anyone?
* IMPORTANT FACT *
on the preview, it does work but it doesn't when I run it
My problem is that for some reason when I run it the app the fragment
works, the list appears and the items of it are fine, but the header
simply isn't there.
IMPORTANT FACT * on the preview, it does work but it doesn't when I run it
=> Looks like you have misunderstood about tools attribute. Those are design time attributes, means that it's helpful while designing layouts. Yes those are not meant for runtime and so obviously it won't be appeared in app.
To clarify it by giving you an example, android:text="Hello World and tools:text="Hello World". You should put demo/testing data in layout using tools attribute so user will not be seeing those data but it will be helpful to developers to see that there are views available in layout. In fact, they can adjust margins, paddings and all other layout design time operations!

Android RelativeLayout UI not displayed properly

I am trying to use RelativeView as part of the RecyclerView. But the UI is not displayed properly. Below is the xml which I am using for the relativelayout
<?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:orientation="vertical">
<CheckBox
android:id="#+id/list_item_crime_solved_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="4dp"/>
<TextView
android:id="#+id/list_item_crime_title_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/list_item_crime_solved_check_box"
android:textStyle="bold"
android:padding="4dp"
tools:text="Crime Title"/>
<TextView
android:id="#+id/list_item_crime_date_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/list_item_crime_solved_check_box"
android:layout_below="#id/list_item_crime_title_text_view"
android:padding="4dp"
tools:text="Crime Date"/>
</RelativeLayout>
When I run it in emulator I get below display
As I am learning android programing I am not getting what could be the cause that the item are not listed below each item and there is lot of gap coming up between two items.
Just change the height of RelativeLayout from match_parent to wrap_content. i.e.
<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="wrap_content">
Just update layout height to wrap_content, Refer below code snippet,
<?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="wrap_content"
android:background="#ff0000"
android:orientation="vertical">

ListView Selector on Specific Element Within ListView View

I'm having a problem where I want each subchild of a view for a listview to have it's own custom selector. There are a few solutions already but none of them seem to work at all for me. Here's my xml for the listview and individual view. Does anyone know specifically what I need to do? Right now If I can get show_group_actions and action_calendar to have separate selectors working I'd be quite happy...
<?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="wrap_content"
android:descendantFocusability="afterDescendants"
android:orientation="vertical">
<LinearLayout
android:id="#+id/action_show_group_actions"
style="#style/AppTheme.NavigationDrawer.Row"
android:paddingRight="0dp"
>
<TextView
android:id="#+id/group_name"
style="#style/AppTheme.NavigationDrawer.Row.TextView"
android:text="#string/label_my_groups"
/>
<RelativeLayout
style="#style/AppTheme.NavigationDrawer.Group.OpenClose"
>
<me.magneto.groups.views.IconView
android:id="#+id/action_show_group_actions_arrow"
style="#style/AppTheme.NavigationDrawer.Group.OpenClose.Arrow"
android:text="#string/icon_chevron_down"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/action_calendar"
style="#style/AppTheme.NavigationDrawer.Group.Row"
>
<me.magneto.groups.views.IconView
style="#style/AppTheme.NavigationDrawer.Group.IconView"
android:text="#string/icon_calendar"
/>
<TextView
style="#style/AppTheme.NavigationDrawer.Row.TextView"
android:text="#string/label_calendar"/>
</LinearLayout>
</LinearLayout>
<ListView
android:id="#+id/navigation_drawer_list_view"
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:listSelector="#null"
android:background="#color/navigation_primary_background"
/>

Android: How do I access my main layout with an id (which i had provided in xml) in my class?

I basically want to access my layout so that I can move onto the next screen when the user clicks anywhere on the present screen.
this is my xml code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/hellolayout">
<TextView
android:text="WELCOME!"
android:textSize="50dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.9"
android:id="#+id/textView1"
android:layout_centerHorizontal="true" />
<ImageView
android:src="#drawable/idiotic_smile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:id="#+id/imageView1" />
</LinearLayout>
In the class, 'hellolayout' is not recognized. Is there anything I'm missing to include?
LinearLayout l = FindViewById<LinearLayout> (Resource.Id.hellolayout);
Acessing a layout should be as simple as R.layout.YourLayoutName. To load it use setContentView(R.layout.YourLayoutName).
Better refer to the docs here.

how to insert layout to layout in android?

I've got two layouts first and second, I want to insert second to first.
I want to insert second layout into layout that has id #+id/layout
when I press button Get Layout, it show the the second layout on the bottom of button
first layout
<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" >
<Button
android:id="#+id/btn_get_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Layout" />
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
second 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:background="#drawable/card_base"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/img_cover"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:scaleType="fitXY"
android:src="#drawable/card_beauty" />
<ImageView
android:id="#+id/img_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="20dp"
android:scaleType="fitXY"
android:src="#drawable/sample_0" />
</RelativeLayout>
</LinearLayout>
if I understood you right you should use the following code within your first layout
<include
layout="#layout/second_layout"
android:id="#+id/includedLayout"
android:visibility="gone"
android:layout_below="#id/buttonId" />
and then in your button's action you just use
((RelativeLayout)findViewById(R.id.includedLayout)).setVisibility(View.VISIBLE);
LinearLayout placeHolder = (LinearLayout) findViewByid(R.id.layout);
getLayoutInflater().inflate(R.layout.second_layout, placeHolder);
Use include
Here is a somewhat fuller example. The square blue layout is inserted into the main layout using include.
activity_main.xml
This is the main layout. The custom layout is referenced using include. You can override any of the attributes here, too.
<?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"
android:padding="16dp">
<!-- Here is the inserted layout -->
<include layout="#layout/my_layout"/>
</RelativeLayout>
my_layout.xml
This is the custom layout that will be inserted into the main layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="5dp"
android:text="My Layout"/>
</RelativeLayout>
You Should use this code snippet to add a Layout inside another one.
parentLayout=(LinearLayout)findViewById(R.id.parentLayout);
inflateView=View.inflate(this,R.layout.view_video,parentLayout);
Here the parentLayoutis the root View and R.layout.view_video is the layout that you need to insert.
Use LayoutInflator to inflate an external layout into existing layout. Checkout LayoutInflater on Android Dev Site for more information about it.

Categories

Resources