Changing view order in the program - android

My main.xml has ListView and ImageView. Now ListView is behind the ImageView. How can I make when the user touch the screen, the ImageView is put behind the ListView. How can I implement in the program? My main.xml is as follow.
<?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="match_parent"
android:orientation="vertical"
>
<LinearLayout android:id="#+id/tracker_container"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="vertical"
/>
<ImageView
android:id="#+id/imageView1"
android:contentDescription="#string/display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/im1"
/>
</LinearLayout>

You can try bring the list view to the top by using
listView.bringToFront()

Related

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: tile bitmap in ListView item

I am trying to add a sidebar image to some of the items in a ListView.
The image should occupy the full height of the item and be repeated vertically if necessary.
Stretching the image is not an option.
After trying a few things I ended up modifying the code found here.
Unfortunately, it does not seem to work within a ListView and the image is not repeated:
Main 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: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=".MainActivity" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
ListView item layout:
<?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="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical">
<ImageView
android:id="#+id/listitem_sidebar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/sidebar"
android:visibility="invisible"/>
</LinearLayout>
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:text="Test"
android:layout_alignParentRight="true"/>
</RelativeLayout>
Background drawable:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/sidebar"
android:tileMode="repeat" />
Background image:
Setting the sidebar globally for the whole ListView is not an option as I am using different View types for the items in my production code.
Edit: formatting
Alight, finally got it to work just the way I wanted. I added a transparent View below the TextView to force the ListView to measure the item's height and do a layout pass. Then I used the invisible View as an anchor for my side bar.
The only file that needed to be modified was listview_item.xml:
<?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="wrap_content" >
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:layout_alignParentRight="true"
android:text="Test"/>
<View
android:id="#+id/dummy"
android:layout_below="#id/textview"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/background"
android:layout_alignParentTop="true"
android:layout_above="#id/dummy"
android:orientation="vertical">
<ImageView
android:id="#+id/listitem_sidebar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/sidebar"
android:visibility="invisible"/>
</LinearLayout>
</RelativeLayout>
Here's a screenshot of the result:
I removed the code for my previous workaround as it was more of a hack than anything and didn't work as well as this.

How to show other views after list view height set to fill_parent

To prevent multiple GetView calling I have set the height of ListView to fill_parent.
How to show other views than the ListView itself?
The following layout is inflated in a ViewPager:
<?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:padding="15dp" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
where the included layout is:
<?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"
android:padding="20dp" >
<ScrollView
android:id="#+id/prontuariohome_scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none" >
.
.
.
.
</ScrollView>
</LinearLayout>
EDIT: This solution won't work for view higher than a button
I don't understand what you want to achieve, but if you NEED to have the height as fill_parent for some reason and can't be any other value, you can put the ListView with inside a LinearLayout with the height="0dp" and weight="1". So would be something 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"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
Try to use following code
android:layout_height="0dp"
android:layout_weight="1"
in ListView tag
With android:layout_height="0dip" the view will take the rest of the free place
You said this solution is wont work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/lv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" android:layout_above="#+id/bt"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bt" android:layout_alignParentBottom="true"/>
just add it a android:layout_above="#+id/bt" to listview.
I'm sorry for being not clear.
Here is the link of the (probably) main thread asked here in Sof about the issue I was talking about.
After some tries I'm happy to give you the solution of my problem.
Giving another layout above the ListView lets the LV cuts the space not filled by the ListView itself
<?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:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>

How to create a LinearLayout with TextView and Image on each row to fill up screen height

I am trying to achieve the below layout in my Android Application.
I achieved this layout by using a custom List Adapter. But the problem is with the empty space in the bottom. Is it possible to make the ListView items be evenly spaced to occupy the entire screen height.
One alternative is to use LinearLayout with WeightSum. But with this approach, how will I be able to place textView and the arrow image in the same row.
Any suggestion to achieve this layout and evenly distribute row height would be appreciated.
Thank you in advance.
Main Activity 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"
android:background="#color/startscreen_background"
tools:context=".StartScreen" >
<ListView
android:id="#+id/start_lv_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:divider="#color/startscreen_listitem_divider"
android:dividerHeight="0px" >
</ListView>
</RelativeLayout>
List Item 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" >
<TextView
android:id="#+id/startscreen_tv_item"
android:layout_width="match_parent"
android:layout_height="#dimen/startscreen_listitem_height"
android:gravity="center_vertical"
android:paddingLeft="#dimen/startscreen_listitem_paddingleft"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/startscreen_listitem_textcolor"
android:textSize="#dimen/startscreen_listitem_textsize" />
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:background="#color/startscreen_listitem_divider" />
</LinearLayout>
You can use android:layout_height="fill_parent" in your Main Activity XML:
<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:background="#color/startscreen_background"
tools:context=".StartScreen" >
<ListView
android:id="#+id/start_lv_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:divider="#color/startscreen_listitem_divider"
android:dividerHeight="0px" >
</ListView>
</RelativeLayout>
Did you tried giving the layout_height="match_parent" to your ListView ?

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