Android data binding and included layout doesn't update visibility - android

Hi I have made layout with couple of ImageView and TextView elements due to reduction of code duplication.
I have occurred to two problems:
I need to update these elements inside of layout using data binding, but I don't know how can I access to them in order to update images and texts?
The visibility of layout should be bind from VM object(default visibility is GONE) but it doesn't work. Even if I update VM setter for visibility, the layout is till visible on the screen.
The code:
included 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">
<LinearLayout
android:id="#+id/details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FF0000">
<ImageView
android:id="#+id/image_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/text_details"
android:text="details"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/favorites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#00FF00">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="details"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#0000FF">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="details"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/remind_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FF0000">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="details"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/return_to_begin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#00FF00">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="details"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
activity layout(this is a snippet, the whole xml is too large)
<include layout="#layout/manu_layout"
android:layout_above="#+id/info"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="#{vm.infoMenu}"/>
viewModel method for visibility:
public void setInfoMenu() {
if(menuVisibility == View.VISIBLE){
menuVisibility = View.GONE;
setMediaControlView(false);
}else {
menuVisibility=View.VISIBLE;
setMediaControlView(true);
}
notifyPropertyChanged(BR.infoMenu);
}
#Bindable
public int getInfoMenu(){
return menuVisibility;
}
Please let me know if you need any additional code snippet.
Can you please help me to solve these problems?
Thanks,
Hogar

Make sure you have <layout> as a root tag of your xml file if you want to use DataBinding.
You can have a id of your <include> and acceess controls of included layout via it. For example you have a id as 'included' of your <include> then you can access it as binding.included.details or binding.included.favourite

Related

updating design and support libs broke UI

currently we are using design and support libs 23.1.1 , when i updated to 25 there is a big gap in the layout and i can't figure out why
unfortunately i need more reputation to post links , all the links inside the file , sorry.
https://gist.github.com/xxqxpxx/a652a0c26a132913cd67faf21a670515
included files : build.gradle , layoutfile.xml , fragmentfile.xml , mainactivity ,activity1.
screenshot before :
screenshot after :
In your layout file change the root Linear layout height form match_parent to wrap_content
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/authors_and_publishers_simpleDraweeView_margin_left"
android:orientation="vertical">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/authors_and_publishers_simpleDraweeView"
android:layout_width="#dimen/author_publishers_simpledraweeview"
android:layout_height="#dimen/author_publishers_simpledraweeview"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/authors_publishers_name_layout_margin_top"
android:orientation="vertical">
<com.kotobi.widget.fonts.views.textviews.RobotoLight
android:id="#+id/authorName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:lines="1"
android:text="Name"
android:textSize="#dimen/author_publisher_pop_up_followrs_text_size" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/authors_and_publishers_simpleDraweeView_margin_top">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="#dimen/author_publisher_pop_up_image_dimen"
android:layout_height="#dimen/author_publisher_pop_up_image_dimen"
android:layout_gravity="center_vertical"
android:layout_marginRight="#dimen/author_publisher_pop_up_image_dimen_margin_right"
android:background="#drawable/followers" />
<com.kotobi.widget.fonts.views.textviews.RobotoLight
android:id="#+id/numberOfFollowers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="12"
android:textColor="#color/grey"
android:textSize="#dimen/author_publisher_pop_up_followrs_number_books" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
<ImageView
android:layout_width="#dimen/author_publisher_pop_up_image_dimen"
android:layout_height="#dimen/author_publisher_pop_up_image_dimen"
android:layout_gravity="center_vertical"
android:layout_marginRight="#dimen/author_publisher_pop_up_image_dimen_margin_right"
android:background="#drawable/number_books" />
<com.kotobi.widget.fonts.views.textviews.RobotoLight
android:id="#+id/numberOfBooks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="12"
android:textColor="#color/grey"
android:textSize="#dimen/author_publisher_pop_up_followrs_number_books" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

Editing SystemUI Layout XMLs

I'm trying to modify my SystemUI so that the cellular signal status more resembles AOSP. I've replaced the necessary images, but now the layout isn't right.
Right now, it looks like this:
On AOSP, it looks like this:
The goal is to have the E icon and the data arrows actually overlap with the signal bar triangle.
I found the proper XML (/res/layout/mobile_signal_group.xml) in the SystemUI APK. This is the original:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="#id/mobile_slot" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingStart="#dimen/signal_cluster_padding"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res-auto">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="#id/slot_no_sims" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="#string/accessibility_no_sims" />
<LinearLayout android:orientation="horizontal" android:id="#id/data_combo" android:layout_width="wrap_content" android:layout_height="wrap_content">
<FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="#id/data_type" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="#id/data_inout" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</FrameLayout>
</LinearLayout>
<FrameLayout android:id="#id/mobile_combo" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="#id/mobile_sim_icon" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<com.android.systemui.statusbar.AnimatedImageView android:theme="#style/DualToneLightTheme" android:id="#id/mobile_signal" android:layout_width="wrap_content" android:layout_height="wrap_content" systemui:hasOverlappingRendering="false" />
<com.android.systemui.statusbar.AnimatedImageView android:theme="#style/DualToneDarkTheme" android:id="#id/mobile_signal_dark" android:layout_width="wrap_content" android:layout_height="wrap_content" android:alpha="0.0" systemui:hasOverlappingRendering="false" />
<ImageView android:id="#id/mobile_type" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:layout_gravity="end|bottom|center" android:id="#id/mobile_inout" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</FrameLayout>
<FrameLayout android:id="#id/mobile_combo_2stage" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:layout_gravity="bottom|center" android:id="#id/data_signal" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="#id/data_rat_type" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="#id/voice_signal" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="#id/voice_rat_type" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</FrameLayout>
</LinearLayout>
</FrameLayout>
I modified it by taking #id/data_type and #id/data_inout and moving them to be right below #id/mobile_sim_icon:
<FrameLayout android:id="#id/mobile_combo" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="#id/mobile_sim_icon" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="#id/data_type" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="#id/data_inout" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<com.android.systemui.statusbar.AnimatedImageView android:theme="#style/DualToneLightTheme" android:id="#id/mobile_signal" android:layout_width="wrap_content" android:layout_height="wrap_content" systemui:hasOverlappingRendering="false" />
<com.android.systemui.statusbar.AnimatedImageView android:theme="#style/DualToneDarkTheme" android:id="#id/mobile_signal_dark" android:layout_width="wrap_content" android:layout_height="wrap_content" android:alpha="0.0" systemui:hasOverlappingRendering="false" />
<ImageView android:id="#id/mobile_type" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:layout_gravity="end|bottom|center" android:id="#id/mobile_inout" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</FrameLayout>
(Abridged code snippet)
But when I do this and flash with the modified XML, SystemUI goes into a crash-start loop. It seems like any change I make to the XML causes this. I'm rather new to this, so maybe I'm missing a step.
So far I've tried:
Moving data-type, data-inout into the other FrameLayout
Moving the whole LinearLayout into the FrameLayout
Wrapping the data_combo LinearLayout around the mobile_combo FrameLayout
All result in SystemUI getting stuck in the crash loop.
Is there anything else I can try?
Device:
LG V20 T-Mobile (H918)
Android 7.0
As discussed in the chat, the SystemUI is crashing due to a NullPointerException when you move #id/data_type and #id/data_inout outside of #id/data_combo. This is because findViewbyId() is being called against R.id.data_combo, and so is looking for a direct descendant of #id/data_combo.
As you don't have access to the Java sources, one workaround is to wrap #id/data_combo around #id/mobile_combo so that #id/data_type and #id/data_inout remain direct descendants of #id/data_combo. For example:
<LinearLayout android:id="#id/data_combo" ... >
<FrameLayout android:id="#id/mobile_combo" ... >
...
</FrameLayout>
</LinearLayout>

Android: fill relative layout height (item layout) inside ListView

I'm not able to make a View that fill the height of a RelativeLayout, which is the layout of ListView items. Here is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:id="#+id/fill_the_height_please"
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="#color/red"/>
<TextView
android:id="#+id/delivery_list_item_dest"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/fill_the_height_please"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:text="Destinatario" />
<TextView
android:id="#+id/delivery_list_item_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/delivery_list_item_dest"
android:layout_below="#id/delivery_list_item_dest"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:text="Location" />
<ImageButton
android:id="#+id/delivery_list_item_mapBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="0dp"
android:src="#drawable/map_location"
android:background="#null" />
View with id fill_the_height_please not fill the item height. In figure below you can see the result (nothing is shown):
I'd like something like this:
รน
I have also try to change view layout as follows but not works anyway:
<View
android:id="#+id/fill_the_height_please"
android:layout_width="15dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:background="#color/red"/>
Please can you help to achieve my goal? Thank you.
One suggestion would be add layout_alignTop="#+id/delivery_list_item_mapBtn" and layout_alignBottom="#+id/delivery_list_item_mapBtn" to the View and make it always fit the image height.
Try changing
android:layout_toRightOf="#id/delivery_list_item_statusBtn"
to
android:layout_toRightOf="#id/fill_the_height_please"
You don't have delivery_list_item_statusBtn. But i see red part even without changing this. Try it and if it doesn't help please post code of your adapter.
Looking here it seems RelativeLayout has a bug in version 17 and lower. So i have change my layout as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:id="#+id/fill_the_height_please"
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="#color/red"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:id="#+id/delivery_list_item_dest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Destinatario"
android:layout_marginBottom="5dp" />
<TextView
android:id="#+id/delivery_list_item_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location" />
</LinearLayout>
<ImageButton
android:id="#+id/delivery_list_item_mapBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="0dp"
android:src="#drawable/map_location"
android:background="#null" />
</RelativeLayout>
A little bit more complex but works. However i leave the question unresolved in case someone find a solution using only a RelativeLayout

Use a vertical line in a ListView item

I'm trying to show a vertical line in an android ListView item. I define it in the XML for the cell but when I preview it in the ListView it doesn't appear.
I understand this is an issue because I see alot of questions on here, but don't see any real answer.
The XML is pretty standard:
Cell:
<?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:background="#color/appWhite" >
<View android:layout_width="5dp"
android:layout_height="match_parent"
android:background="#color/appGreen"
android:layout_alignParentLeft="true" />
<RelativeLayout
android:id="#+id/cell_trip_info_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/vertical_bar" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cell_trip_name"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:textColor="#2c3e50"
android:paddingLeft="10dp"
android:text="adfadf" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cell_trip_country"
android:layout_below="#+id/cell_trip_name"
android:textColor="#2c3e50"
android:paddingLeft="10dp"
android:text="adfadf" />
</RelativeLayout>
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/whole_container"
android:layout_alignParentRight="true" >
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/appGreen"
android:id="#+id/cell_trip_date_box"
android:layout_alignTop="#+id/update_buttons"
android:layout_alignBottom="#+id/update_buttons"
android:padding="20dp" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cell_tripstart_date"
android:layout_centerHorizontal="true"
android:textColor="#fff" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cell_date_thru"
android:text="#string/thru"
android:layout_below="#+id/cell_tripstart_date"
android:layout_centerHorizontal="true"
android:textColor="#fff" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cell_tripend_date"
android:layout_below="#+id/cell_date_thru"
android:textColor="#fff"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/update_buttons"
android:visibility="gone"
android:layout_toRightOf="#+id/cell_trip_date_box"
android:background="#e9e9e9"
android:padding="20dp" >
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/cell_button_edit_trip"
android:src="#drawable/slide_edit"
android:adjustViewBounds="true"
android:contentDescription="#string/content_description" />
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/cell_button_delete_trip"
android:src="#drawable/slide_delete"
android:layout_toRightOf="#+id/cell_button_edit_trip"
android:adjustViewBounds="true"
android:contentDescription="#string/content_description" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
I found the cause and the obvious solution/workaround on another post Here
Basically RelativeLayouts for whatever reason won't play nice with the "match_parent" height setting in a ListView Item. One of the answer to the post recommended using a LinearLayout instead. So I just created a new File with the parent view being a LinearLayout. I then created a RelativeLayout child and tossed everything else in there.
It worked fine this time, easily allowing me to create my vertical rule.
In your cell_trip_info_container RelativeLayout you have
android:layout_toRightOf="#+id/vertical_bar"
You dont have a View named vertical_bar
Add that ID to your vertical bar view and you should be good to go
<View
android:id="#+id/vertical_bar"
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="#color/appGreen"
android:layout_alignParentLeft="true" />
change
RelativeLayout
to
VerticalLayout

How to hide all elements in a Layout in Android at once?

I'm developing an Android app in eclipse.
I have an XML which has 2 linear layouts next to each other. The left one has several buttons, which make content visible in the right. However, I would not only like these buttons to make specific content visible, but hide (setVisibility.GONE) all the other stuff in that layout. I have already tried removeAllViews, but this is not suitable for me since it deletes them. So my idea is to hide (set the visibility to gone) every single stuff, then make the ones I wish visible. The reason I ask this is that it takes too much time setting the visibility to gone for everything (24, actually) for all the 12 buttons.
Thanks in advance
Layout code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/alap"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageView3"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView4" >
<LinearLayout
android:layout_width="197dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/lewis" />
<Button
android:id="#+id/first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/first" />
<Button
android:id="#+id/second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/second" />
</LinearLayout>
</ScrollView>
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:scaleType="center"
android:src="#drawable/cpr1" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="center"
android:src="#drawable/epizodok" />
<LinearLayout
android:id="#+id/def"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageView3"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/scrollView2"
android:layout_toRightOf="#+id/scrollView2"
android:orientation="vertical"
android:visibility="visible" >
<ImageView
android:id="#+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/lewis"
android:visibility="gone" />
<ImageView
android:id="#+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
Please try this...
<LinearLayout
android:id="+id/ll"
android:layout_width="197dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- All content which you hide/show put here -->
</LinearLayout>
now in your class file you read this.
LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
after that as per your requirement you hide/show this Layout with their all contents.
like:
For Hide.
ll.setVisibility(View.GONE);
For Show.
ll.setVisibility(View.VISIBLE);
when you hide/show LinearLayout all content with this Layout also hide/show automatically.
Simply, Just take another Linear Layout with vertical layout within your "def" Linear layout..Nd change its visibility as per your need.
<LinearLayout
android:id="#+id/def"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageView3"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/scrollView2"
android:layout_toRightOf="#+id/scrollView2"
android:orientation="vertical"
android:visibility="visible" >
<LinearLayout
android:id="#+id/Subdef"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/lewis"
android:visibility="gone" />
<ImageView
android:id="#+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
No need to hide views instead of that just use ViewFlipper concept.
Just declare view flipper in your xml file with your two linearlayouts like this
<Viewflipper android:id="#+id/myViewFlipper" android:layout_height="wrap_content" android:layout_width="match_parent">
<LinearLayout android:id="#+id/layout1" android:layout_height="wrap_content" android:layout_width="match_parent"></LinearLayout>
<LinearLayout android:id="#+id/layout2" android:layout_height="wrap_content" android:layout_width="match_parent"></LinearLayout>
</Viewflipper>
And get viewflipper reference in your java code like this
Viewflipper mFlipper = (Viewflipper)findViewById(R.id.myViewFlipper);
use mFlipper.showNext(), use mFlipper.showPrevious() methods to hide and show your layouts thats it.

Categories

Resources