Android view layout component on top of each other - java

I was having some problem with the layout of Android Activity. So basically I have a navigation drawer and two Activity. The layout was working perfectly when I wrap all of them with a frame layout. However, because of the navigation drawer issues, I have to remove the frame layout into another xml layout. And then from there, my layouts were all messed up. Here is my layout.xml:
<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">
<com.esri.android.map.MapView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="100dp"
initExtent="21801.3, 25801.0, 33218.7, 44830.0" >
</com.esri.android.map.MapView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_marginLeft="45dp" >
<ImageView
android:id="#+id/ivEventGuide"
android:layout_width="230dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="#drawable/event_create_guide"
android:visibility="gone" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/btnNewsFeed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/lightred"
android:minHeight="20dp"
android:paddingBottom="5dp"
android:text="News feed"
android:textColor="#FFFFFF"
android:textSize="13dp" />
<LinearLayout
android:id="#+id/llNewsFeed"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/btnNewsFeed"
android:background="#FFFFFF"
android:orientation="vertical"
android:visibility="gone" >
<ListView
android:id="#+id/EventNewsFeedListview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="#F6CECE" >
</ListView>
</LinearLayout>
<Button
android:id="#+id/btnLegends"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnNewsFeed"
android:background="#FFFFFF"
android:minHeight="20dp"
android:paddingBottom="5dp"
android:text="Legends"
android:textColor="#color/lightred"
android:textSize="13dp" />
<LinearLayout
android:id="#+id/legendDiv"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="#+id/btnLegends"
android:background="#fff"
android:orientation="vertical"
android:visibility="gone" >
<TableLayout
android:id="#+id/tableEvent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp" >
<ImageView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/food" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:paddingTop="10dp"
android:text="Food Event"
android:textColor="#000"
android:textSize="10dp" />
<ImageView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/sport" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:paddingTop="10dp"
android:text="Sport Event"
android:textColor="#000"
android:textSize="10dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="2dp" >
<ImageView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/races" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:paddingTop="10dp"
android:text="Festival Celebration"
android:textColor="#000"
android:textSize="10dp" />
<ImageView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/discussion" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:paddingTop="10dp"
android:text="Chit Chat Session"
android:textColor="#000"
android:textSize="10dp" />
</TableRow>
</TableLayout>
</LinearLayout>
<TextView
android:id="#+id/tvSearchTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/llSearch"
android:background="#color/lightred"
android:gravity="center"
android:paddingBottom="5dp"
android:text="Address Search"
android:textColor="#FFFFFF" >
</TextView>
<LinearLayout
android:id="#+id/llSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FFFFFF"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="1" >
<EditText
android:id="#+id/searchAddrET"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="0.8"
android:hint="Enter search address, eg. postal code"
android:textSize="12dp" />
<Button
android:id="#+id/btnSearchAddr"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="0.2"
android:background="#color/lightred"
android:minHeight="30dp"
android:text="Search"
android:textColor="#FFFFFF"
android:textSize="12dp" />
</LinearLayout>
<TextView
android:id="#+id/tvDirectionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/llDirection"
android:background="#color/lightred"
android:gravity="center"
android:paddingBottom="5dp"
android:text="Direction"
android:textColor="#FFFFFF"
android:visibility="gone" >
</TextView>
<LinearLayout
android:id="#+id/llDirection"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:background="#FFFFFF"
android:padding="5dp"
android:visibility="gone" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvDirection"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TextView>
</ScrollView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
When it was working fine, I wrapped the map view and the rests of the layout with a frame layout. And then inside the class where I extended the navigation drawer:
public class EventMain extends NavigationDrawer {
public static MapView mMapView = null;
ArcGISTiledMapServiceLayer tileLayer;
LocationManager locationManager;
public static GraphicsLayer graphicsLayer = null;
public static Callout callout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewGroup content = (ViewGroup) findViewById(R.id.event_frame);
getLayoutInflater().inflate(R.layout.event_main, content, true);
}
The problem that I was having now was all the other components is not showing on top of the map view. Any guides?
Thanks in advance.

You should consider using RelativeLayout for overlapping views. Views inside a RelativeLayout may be positioned relative to their parent and/or siblings. A LinearLayout will arrange views sequentially with no overlap allowed.

Related

Toolbar back arrow with icon

How to display icon with back arrow in android toolbar like WhatsApp ?
I would like to reduce the space between the photo and the back arrow.
How can I reduce space?
I have:
ChatActivity.java: the layout (which has only one view) is replaced with ChatFragment.java. Moreover, the toolbar is replaced here with fragment_chat_toolbar.xml
ChatFragment.java: here the inputs, the emojis, the files etc. are managed
Thanks.
My toolbar chat
fragment_chat.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layout_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="#+id/fragment_chat_recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:gravity="center" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginEnd="4dp"
android:background="#drawable/incoming_message"
android:baselineAligned="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:paddingStart="2dp"
android:paddingEnd="4dp" >
<ImageView
android:id="#+id/image_view_emoji"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginStart="6dp"
android:layout_gravity="center"
android:contentDescription="#string/emoji_button"
android:src="#mipmap/ic_emoji"
android:tint="#color/total_black" />
<com.vanniktech.emoji.EmojiEditText
android:id="#+id/message_box_emoji"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#color/incomingColor"
android:hint="#string/send_message"
app:emojiSize="26sp"/>
<ImageView
android:id="#+id/image_view_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:layout_gravity="center"
android:contentDescription="#string/camera_button"
android:src="#mipmap/ic_camera"
android:tint="#color/total_black" />
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/float_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#mipmap/ic_voice_recorder"
android:tint="#color/white"
app:backgroundTint="#color/colorPrimary"
app:elevation="0dp"
app:fabSize="mini"/>
</LinearLayout>
</LinearLayout>
fragment_chat_toolbar.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:clipChildren="false" >
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/profile_photo"
android:layout_width="50dp"
android:layout_height="50dp"
fresco:failureImage="#drawable/default_profile"
fresco:placeholderImage="#drawable/default_profile"
fresco:roundAsCircle="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="4dp"
android:gravity="start"
android:orientation="vertical" >
<TextView
android:id="#+id/chat_title_text_view"
android:layout_width="wrap_content"
android:textSize="16sp"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="#color/white" />
<TextView
android:id="#+id/chat_subtitle_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="#color/white" />
</LinearLayout>
Make Custom Toolbar as you like. Change your layout in RelativeLayout
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/llLeft"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/transparent_layout_background"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:padding="10dp">
<ImageView
android:id="#+id/ivLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_action_menu" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#+id/llLeft"
android:layout_toLeftOf="#+id/llRight"
android:layout_toRightOf="#+id/llLeft"
android:layout_toStartOf="#+id/llRight"
android:gravity="center">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="#font/roboto_bold"
android:lines="1"
android:text="asdf"
android:textColor="#color/colorWhite"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/llRight"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="#drawable/transparent_layout_background"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:padding="10dp">
<ImageView
android:id="#+id/ivRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_action_search" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>

how to center crop a background image of linear layout?

Hi i had to make a layout with card with recyclerview so for that i set an image as a background to linear layout but now i'm unable to center crop that image
My problem is that i cannot use imageview because using that the height of card increases as well and i don't want that so please if someone can assit me..
my xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/primary_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="15dp"
app:cardCornerRadius="115dp">
<ImageView
android:id="#+id/background_image_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:visibility="gone" />
<LinearLayout
android:id="#+id/background_image"
android:layout_width="match_parent"
android:layout_height="210dp"
android:background="#drawable/club1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:src="#drawable/ellipse" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="John Doe"
android:textColor="#color/White"
android:textSize="15sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="checked in to"
android:textColor="#color/White"
android:textSize="10sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="W south"
android:textColor="#color/White"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="9dp"
android:text="beach mumbai"
android:textColor="#color/White"
android:textSize="15sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/fifth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/second_text"
android:layout_toRightOf="#+id/fourth_text"
android:text="30 mins ago."
android:textColor="#color/White"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="85dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/sixth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:padding="10dp"
android:text="reply to abc............"
android:textColor="#color/White" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/favourite_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ic_favorite_border_black_24dp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/seventh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:text="40 likes"
android:textColor="#color/White" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
You can't center crop a background image of linear layout,
But you can achieve the same using these changes:
Replace you LinearLayout with RelativeLayout
Place a ImageView as a first child inside relative layout and use property for center crop.
<RelativeLayout
android:id="#+id/background_image"
android:layout_width="match_parent"
android:layout_height="210dp"
android:orientation="vertical">
<ImageView
android:scaleType="centerCrop"
android:src="#drawable/club1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
.....
......
</RelativeLayout>
If you Want to control The Image View Scale
you need to put it in ImageView As Src Not Background
You can use Frame layout To Achieve it
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/primary_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="15dp"
app:cardCornerRadius="115dp">
<ImageView
android:id="#+id/background_image_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:visibility="gone" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="210dp">
<ImageView
android:layout_width="match_parent"
android:src="#mipmap/ic_launcher"
android:layout_height="match_parent" />
<LinearLayout
android:id="#+id/background_image"
android:layout_width="match_parent"
android:layout_height="210dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/profile_image"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:src="#drawable/playstore_icon" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="#+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="John Doe"
android:textSize="15sp" />
<TextView
android:id="#+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="checked in to"
android:textSize="10sp" />
<TextView
android:id="#+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="W south"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="9dp"
android:text="beach mumbai"
android:textSize="15sp" />
<TextView
android:id="#+id/fifth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/second_text"
android:layout_toRightOf="#+id/fourth_text"
android:text="30 mins ago."
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="85dp">
<TextView
android:id="#+id/sixth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:padding="10dp"
android:text="reply to abc............"
android:textColor="#color/white" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/favourite_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ic_close" />
<TextView
android:id="#+id/seventh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:text="40 likes"
android:textColor="#color/white" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</android.support.v7.widget.CardView>
CenterCrop logic is baked inside ImageView. The correct solution is to extract it into a Drawable which wraps another Drawable and centerCrops it.
If you use CoordinatorLayout, then just to put your ImageView with centerCrop parameter to top.
<CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:scaleType="centerCrop"
android:background="#drawable/background_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp">
<include layout="#layout/header_main" />
<TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#android:color/white"
android:background="#drawable/white_border_background"
app:tabIndicatorHeight="3dp"/>
</AppBarLayout>
<ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</CoordinatorLayout>

setOnItemClickListener() not working on listView of Fragments

I have some issues with handle click's on my ListView element witch contains customized ArrayAdapter of Fragments. There is no checkbox anywhere, only Button in Fragment is ImageButton and it already has android:focusable="false". In Layout of ListView I have some FrameLayout's, some Buttons and EditText XML code Below. Any solutions like android:focusable="false" ,android:focusableInTouchMode = "false" , list.setItemsCanFocus(false). I searched a lot but nothing helps.
Here is main container for listView with Gmap and listView above:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.medhigh.mapfragmet.MapsActivity" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginRight="8dp"
android:id="#+id/searchLine">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<EditText
android:layout_marginLeft="16dp"
android:layout_marginRight="42dp"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_weight="1"
android:textColor="#color/black"
android:textSize="18sp"
android:hint=" Start Typing Here"
android:textColorHighlight="#color/colorPrimaryTest"
android:textColorHint="#959595" />
<Button
android:id="#+id/clearEditText"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginRight="50dp"
android:layout_gravity="right|center_vertical"
android:background="#drawable/close"
android:focusable="false"/>
</FrameLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.medhigh.mapfragmet.MapsActivity">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="48dp"
android:layout_height="48dp"
android:id="#+id/buttonSwitchToList"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="98dp"
android:layout_marginRight="7dp"
android:background="#drawable/format_list"
android:focusable="false"/>
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBar"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="42dp"
android:layout_marginLeft="42dp"
android:layout_marginBottom="12dp"
android:max="300" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/seekBarProgress"
android:textColor="#color/black"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
tools:context=".search.NameFragment"
android:background="#color/white"
android:id="#+id/layoutList">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<EditText
android:layout_marginLeft="16dp"
android:layout_marginRight="42dp"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTextList"
android:layout_weight="1"
android:textColor="#color/black"
android:textSize="18sp"
android:hint=" Start Typing Here"
android:textColorHighlight="#color/colorPrimaryTest"
android:textColorHint="#959595" />
<Button
android:id="#+id/clearEditTextList"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginRight="10dp"
android:background="#drawable/close"
android:layout_gravity="end|center_vertical"
android:focusable="false"/>
</FrameLayout>
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView"
android:clickable="true" />
<Button
android:id="#+id/buttonBackToMap"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginRight="12dp"
android:layout_marginBottom="24dp"
android:background="#drawable/map"
android:layout_gravity="end|bottom"
android:focusable="false"/>
</FrameLayout>
</LinearLayout> </FrameLayout>
Here is Fragment of List View:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="112dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="#+id/imageView2"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:src="#drawable/news_demo"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Location Name"
android:id="#+id/textViewNewsHeader"
android:textColor="#color/colorPrimaryTest"
android:layout_alignTop="#+id/imageView2"
android:layout_toRightOf="#+id/imageView2"
android:layout_toEndOf="#+id/imageView2" />
<TextView
android:layout_width="wrap_content"
android:lines="4"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginRight="60dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Location description"
android:id="#+id/textViewShortStory"
android:textColor="#color/black"
android:layout_below="#+id/textViewNewsHeader"
android:layout_toRightOf="#+id/imageView2"
android:layout_toEndOf="#+id/imageView2" />
<TextView
android:layout_width="wrap_content"
android:lines="4"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="60dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="5"
android:id="#+id/clinicNumber"
android:textColor="#color/colorPrimaryTest"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/imageButton"
android:layout_marginEnd="13dp" />
<ImageButton
android:layout_width="42dp"
android:layout_height="42dp"
android:id="#+id/imageButton"
android:src="#drawable/arrow_right_black"
android:background="#color/white"
android:scaleType="fitXY"
android:layout_marginRight="20dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:focusable="false"
/>
</RelativeLayout>
Here is some code from view Container class
adapter = new LocationHospitalListFragmentAdapter(getContext(), locationList, R.layout.fragment_search_location_hospital_list);
listView.setAdapter(adapter);
listView.setItemsCanFocus(false);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//show list view layout
Toast.makeText(getActivity().getApplicationContext(),"onItemClick",Toast.LENGTH_SHORT).show();
Log.d("333__","on click");
}
});
add this line to parent layout of ListItem android:descendantFocusability="blocksDescendants"

Push keyboard to layout

I have an edittext, and when I focus on that, the footer layout was pushed together. How to hide footer when focus on edittext.
Before focus
After focus
this is my source code
<ListView
android:id="#+id/list_chat_rom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/rl_footer_send"
android:divider="#android:color/transparent"
android:dividerHeight="5dp"></ListView>
<RelativeLayout
android:id="#+id/rl_footer_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/menu_bar_bg">
<RelativeLayout
android:id="#+id/rl_insert_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp">
<ImageView
android:id="#+id/btn_send_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/layout_imv_send_message" />
<EditText
android:id="#+id/edit_insert_chat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/btn_send_msg"
android:background="#drawable/layout_edit_text_chat"
android:hint="type to filter"
android:inputType="text"
android:maxLines="1"
android:textColor="#color/black" />
</RelativeLayout>
<View
android:id="#+id/view_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#id/rl_insert_chat"
android:background="#color/black"></View>
<RelativeLayout
android:id="#+id/rl_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/view_line"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="10dp"
android:paddingTop="5dp">
<ImageView
android:id="#+id/imv_avatar_chat"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<RelativeLayout
android:id="#+id/rl_content_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/imv_avatar_chat">
<TextView
android:id="#+id/tv_name_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="user name"
android:textColor="#color/white" />
<TextView
android:id="#+id/tv_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_name_user"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="lv : 10"
android:textColor="#color/white" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/target_icon" />
<TextView
android:id="#+id/tv_point_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10/125" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/gem_icon" />
<TextView
android:id="#+id/tv_xu_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="100" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/tv_login_facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#id/imv_avatar_home"
android:text="ĐĂNG NHẬP BẰNG FACEBOOK"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
Why don't you try to hide it?
You can try to detect the keyboard state with this :
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
Note : Taken from here
And then you just hide the view that you want to hide.
Try with
android:windowSoftInputMode="adjustPan"
in the Activity declaration in the manifest

How to make ImageButton always be at the bottom of the screen

I have created a xml design for this case.
But I got a problem when the ListView has finished reading the data and display data to the screen, but then ImageButton later covered/disappear by listView.
My code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E6E6E6"
android:orientation="vertical" >
<TextView
android:id="#+id/tanggal"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#FF2300"
android:fontFamily="sans-serif-light"
android:paddingLeft="10dp"
android:textSize="#dimen/font_size" />
<TextView
android:id="#+id/txtHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/app_name"
android:textColor="#ffffff"
android:textSize="25sp"
android:visibility="gone" />
<com.costum.android.widget.LoadMoreListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:cacheColorHint="#EBEBEB"
android:fadingEdgeLength="0dp"
android:overScrollMode="never"
android:scrollbars="none"
android:visibility="gone" />
<TextView
android:id="#+id/notfound"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:gravity="center"
android:text="#string/notfound"
android:textSize="20sp"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/panelBaru"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<TextView
android:id="#+id/netTrouble"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="#string/txt_failed"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="gone" />
<ProgressBar
android:id="#+id/LoadingData"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:visibility="gone" />
<ImageButton
android:id="#+id/btnImg"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:contentDescription="#null"
android:src="#drawable/coba" />
</RelativeLayout>
</LinearLayout>
I guess at the android:layout_height="match_parent" who make this happen. How do I fix it?
Problem is your list view is match parent so change your xml like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E6E6E6"
android:orientation="vertical" >
<TextView
android:id="#+id/tanggal"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#FF2300"
android:fontFamily="sans-serif-light"
android:paddingLeft="10dp"
android:textSize="#dimen/font_size" />
<TextView
android:id="#+id/txtHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/app_name"
android:textColor="#ffffff"
android:textSize="25sp"
android:visibility="gone" />
<com.costum.android.widget.LoadMoreListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:cacheColorHint="#EBEBEB"
android:fadingEdgeLength="0dp"
android:overScrollMode="never"
android:scrollbars="none"
android:visibility="gone" />
<TextView
android:id="#+id/notfound"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="center"
android:text="#string/notfound"
android:textSize="20sp"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/panelBaru"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
<TextView
android:id="#+id/netTrouble"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/txt_failed"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="gone" />
<ProgressBar
android:id="#+id/LoadingData"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:visibility="gone" />
<ImageButton
android:id="#+id/btnImg"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:contentDescription="#null"
android:src="#drawable/coba" />
</RelativeLayout>
</LinearLayout>
by doing this your list view takes only remaining place. If any Problem Please comment.
Change
<com.costum.android.widget.LoadMoreListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:cacheColorHint="#EBEBEB"
android:fadingEdgeLength="0dp"
android:overScrollMode="never"
android:scrollbars="none"
android:visibility="gone" />
to
<com.costum.android.widget.LoadMoreListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:cacheColorHint="#EBEBEB"
android:fadingEdgeLength="0dp"
android:overScrollMode="never"
android:scrollbars="none"/>
The simplest way is to replace com.costum.android.widget.LoadMoreListView definition
android:layout_height="match_parent"
with
android:layout_height="wrap_content"
The harder way is to change layout of All view from LinearLayout to RelativeLayout.
Then You have to set 'panelBaru' alignParentBottom and with wrap_content height and listView above it
android:layout_alignParentBottom="true"

Categories