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
Related
I have a screen with four EditTexts, any edittext doesn't open the keyboard when I click on it. I'm not using an AVD, I'm using my own device, and tested in others devices and same result.My app has some activities like Login , sigup, home activity. In login and sigup activity edittext works correctly but in fragments of home activity keyboard is not opening.
XML
```
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="100dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="210dp"
android:background="#color/global_bg"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="18dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerVertical="true"
android:src="#drawable/profile"
app:civ_border_color="#color/main_color"
app:civ_border_width="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/profile_image"
android:orientation="vertical">
<TextView
android:id="#+id/fullname_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/bungee"
android:includeFontPadding="false"
android:text="Muneeb Ur Rehman"
android:textColor="#color/black"
android:textSize="19sp" />
<TextView
android:id="#+id/city_field_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/profile_image"
android:includeFontPadding="false"
android:text="user_city"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-80dp"
android:padding="20dp">
<com.google.android.material.card.MaterialCardView
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_margin="10dp"
android:layout_weight="1"
app:cardBackgroundColor="#color/main_color"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:background="#drawable/total_orders"
android:backgroundTint="#color/white" />
<TextView
android:id="#+id/totalOrders"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="#font/bungee"
android:includeFontPadding="false"
android:text="12"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/total_orders_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/totalOrders"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:includeFontPadding="false"
android:text="Total Orders"
android:textColor="#color/white"
android:textSize="18sp" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_margin="10dp"
android:layout_weight="1"
app:cardBackgroundColor="#color/main_color"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:background="#drawable/pending_orders"
android:backgroundTint="#color/white" />
<TextView
android:id="#+id/pendingOrders"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="#font/bungee"
android:includeFontPadding="false"
android:text="0"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/pendingOrders_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/pendingOrders"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:includeFontPadding="false"
android:text="Pending Orders"
android:textColor="#color/white"
android:textSize="18sp" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="19dp"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/profile_edittext_shape"
android:drawableLeft="#drawable/ic_person_black_24dp"
android:drawablePadding="10dp"
android:elevation="3dp"
android:hint="Name"
android:inputType="textPersonName"
android:padding="13dp"
android:textCursorDrawable="#drawable/cursor_color_edittext" />
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/user_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/profile_edittext_shape"
android:drawableLeft="#drawable/ic_baseline_phone_iphone_24"
android:drawablePadding="10dp"
android:elevation="3dp"
android:hint="Mobile Number"
android:inputType="phone"
android:padding="13dp"
android:textCursorDrawable="#drawable/cursor_color_edittext" />
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/user_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/profile_edittext_shape"
android:drawableLeft="#drawable/ic_baseline_location_city_24"
android:drawablePadding="10dp"
android:elevation="3dp"
android:hint="City"
android:inputType="text"
android:padding="13dp"
android:textCursorDrawable="#drawable/cursor_color_edittext" />
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/user_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/profile_edittext_shape"
android:drawableLeft="#drawable/ic_baseline_location_on_24"
android:drawablePadding="10dp"
android:elevation="3dp"
android:hint="Address"
android:inputType="text"
android:padding="13dp"
android:textCursorDrawable="#drawable/cursor_color_edittext" />
<Button
android:id="#+id/btnUpdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#drawable/bg_btn"
android:fontFamily="#font/bungee"
android:text="UPDATE"
app:backgroundTint="#color/main_color" />
<Button
android:id="#+id/btnLogout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/bg_btn"
android:fontFamily="#font/bungee"
android:text="Logout"
app:backgroundTint="#color/main_color" />
</LinearLayout>
</LinearLayout>
</ScrollView>
```
Try using editText.setShowSoftInputOnFocus(true) and editText.setFocusable(true)
Also check your AndoridManifest.xml and add android:windowSoftInputMode="stateAlwaysVisible" to corresponding activity, or adjustResize.
<activity
android:name="com.fortrun.testcrashlytics.MainActivity"
android:windowSoftInputMode="adjustResize" >
</activity>
"adjustResize" The activity's main window is always resized to make
room for the soft keyboard on screen.
"stateAlwaysVisible" The soft keyboard is visible when the window receives input focus.
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>
I've got a fragment from which users select features their rooms have (fig.1 below) and these are stored in the back-end as boolean values i.e. true if set and false otherwise.
The XML for the fragment:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
<!-- none core xml formatting and views -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:weightSum="1"
android:layout_gravity="center_horizontal"
android:background="#drawable/border_bottom_top"
android:id="#+id/details_amenities_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_bic_imageview"
android:src="#mipmap/ic_bic"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_bic_amenity"
android:id="#+id/add_room_bic_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_below="#+id/add_room_bic_imageview" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_entrance_imageview"
android:src="#mipmap/ic_entrance"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_entrance_amenity"
android:id="#+id/add_room_entrance_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_toilet_imageview"
android:src="#mipmap/ic_toilet"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_toilet_amenity"
android:id="#+id/add_room_toilet_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_kitchen_imageview"
android:src="#mipmap/ic_kitchen"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_kitchen_amenity"
android:id="#+id/add_room_kitchen_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:layout_marginTop="8dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_parking_imageview"
android:src="#mipmap/ic_parking"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_parking_amenity"
android:id="#+id/add_room_parking_label"
android:textSize="16sp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/add_room_parking_imageview" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_wifi_imageview"
android:src="#mipmap/ic_wi_fi"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_wifi_amenity"
android:id="#+id/add_room_wifi_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_secure_imageview"
android:src="#mipmap/ic_secure"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_secure_amenity"
android:id="#+id/add_room_secure_label"
android:textSize="16sp"
android:gravity="center"
android:layout_below="#+id/add_room_secure_imageview"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:id="#+id/add_room_furnished_imageview"
android:src="#mipmap/ic_furnished"
style="#style/amenities_image_style"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_furnished_amenity"
android:id="#+id/add_room_furnished_label"
android:textSize="16sp"
android:gravity="center"
android:layout_below="#+id/add_room_furnished_imageview"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:layout_marginTop="5dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_borehole_imageview"
android:src="#mipmap/ic_borehole"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_borehole_amenity"
android:id="#+id/add_room_borehole_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_prezesa_imageview"
android:src="#mipmap/ic_zesa"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_zesa_amenity"
android:id="#+id/add_room_prezesa_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/add_room_prezesa_imageview"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_wardrobe_imageview"
android:src="#mipmap/ic_wardrobe"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_wardrobe_amenity"
android:id="#+id/add_room_wardrobe_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_prewater_imageview"
android:src="#mipmap/ic_prewater"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_water_amenity"
android:id="#+id/add_room_prewater_label"
android:textSize="16sp"
android:gravity="center"
android:layout_below="#+id/add_room_prewater_imageview"
android:layout_alignRight="#+id/add_room_prewater_imageview"
android:layout_alignEnd="#+id/add_room_prewater_imageview"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<!-- none core views -->
<android.support.design.widget.FloatingActionButton android:id="#+id/add_room_step3_fab"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end"
android:src="#mipmap/ic_done_white_48dp"
android:layout_marginBottom="#dimen/fab_margin" />
</LinearLayout>
</ScrollView>
Naturally the selected features differ thus the number of views is not constant obtained from the back-end. I am able to retrieve the set features and instantiate the correct views in Java i.e. if there are 5 set features comprising BIC, Wifi, Kitchen etc, I am able to determine these and set the necessary Image resources and Text.
Question now is how do I arrange the views obtained to replicate the layout above using Java code as I can only know the features set after querying the back-end. Desired end result has to look like the image below. Hope it makes sense.
I have an image and some text and below that i have a sliding tab layout with a view pager and the view pager has 3 fragments each having one recycler view each . Now my problem is that i want to scroll the recyclerview and at the same time i want to scroll the rest of the elements too. For eg when i scroll the recycler view i want all other views to scroll as well. This my XML layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="match_parent" android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView7"
android:src="#drawable/aal"
android:adjustViewBounds="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#98000000"
android:id="#+id/innerColor"
android:layout_alignBottom="#+id/imageView7"
android:layout_alignParentTop="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/include"
android:padding="13dp"
>
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:clickable="true"
android:background="#drawable/custom_bg"
android:onClick="BackPressed"
android:src="#drawable/ic_arrow_back"
android:id="#+id/imageView2" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:clickable="true"
android:src="#drawable/add"
android:id="#+id/addAction"
android:onClick="showImage"
android:background="#drawable/custom_bg"
android:tint="#color/icons"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sample "
android:textSize="22sp"
android:id="#+id/textHeader"
android:textColor="#ffffff"
android:layout_marginLeft="12dp"
android:scaleType="centerCrop"
android:layout_above="#+id/descText"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:id="#+id/descText"
android:layout_marginLeft="12dp"
android:text="Sampletext"
android:layout_above="#+id/Fbutton"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Follow"
android:onClick="followUnfollow"
android:background="#drawable/follow_button_bg"
android:stateListAnimator="#null"
android:textColor="#403e3e"
android:padding="5dp"
android:id="#+id/Fbutton"
android:layout_alignParentBottom="true"
android:layout_marginBottom="150dp"
android:layout_centerHorizontal="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Fbutton"
android:layout_marginTop="-80dp"
android:id="#+id/relativeLayout5"
android:layout_centerHorizontal="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relStatMem"
android:layout_alignTop="#+id/relativeLayout5"
android:layout_toEndOf="#+id/relativeLayout5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/numImages"
android:text="500"
android:textColor="#ffffff"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/texts"
android:textSize="12dp"
android:textColor="#ffffff"
android:text="PHOTOS"
android:layout_marginLeft="30dp"
android:layout_below="#+id/numImages"
android:layout_centerHorizontal="true" />
<View
android:layout_width="1dp"
android:layout_height="60dp"
android:background="#ffffff"
android:layout_marginLeft="80dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relStatFol"
android:layout_alignTop="#+id/relStatMem"
android:layout_toEndOf="#+id/relStatMem">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/numMembers"
android:text="5"
android:textColor="#ffffff"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textsMembers"
android:textSize="12dp"
android:textColor="#ffffff"
android:text="MEMBERS"
android:layout_marginLeft="30dp"
android:layout_below="#+id/numMembers"
android:layout_centerHorizontal="true" />
<View
android:layout_width="1dp"
android:layout_height="60dp"
android:background="#ffffff"
android:layout_marginLeft="80dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relStatFols"
android:layout_alignTop="#+id/relStatFol"
android:layout_toEndOf="#+id/relStatFol">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/numFolls"
android:text="1B"
android:textColor="#ffffff"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textsFol"
android:textSize="12dp"
android:textColor="#ffffff"
android:text="FOLLOWERS"
android:layout_marginLeft="30dp"
android:layout_below="#+id/numFolls"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<!--In addition to the two java files we got from google git , this is what you need for tabs-->
<com.example.skmishra.plates.Library.SlidingTabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_below="#+id/innerColor"
android:layout_height="wrap_content">
<!--For elevation add here-->
</com.example.skmishra.plates.Library.SlidingTabLayout>
<android.support.v4.view.ViewPager android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#id/tabs"
android:id="#+id/viewPager"
android:fillViewport="false">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</ScrollView>
Google + Does that , i would like to implement something simillar
I believe Google used a Collapsing Toolbar Layout, which will collaps the toolbar on scroll or other events.
You can find more information here.
<android.support.design.widget.AppBarLayout
android:layout_height="192dp"
android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
I have the code below and I face a problem with the image view "#+id/logo_skilfull" because it does not keep the aspect.. I think is because of the scaleType or the adjustViewBounds..
image in tablet
image in a phone (I want this)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:keepScreenOn="true" >
<View
android:id="#+id/view"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/view2"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/view"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/registration_background"
android:orientation="vertical"
android:padding="25dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/member_login_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="Ingresá tu DNI"
android:textSize="25dp"
android:textStyle="bold"
android:typeface="monospace" />
<EditText
android:id="#+id/username_edtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/member_login_tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:background="#drawable/register_uname"
android:gravity="center"
android:hint="Documento"
android:imeOptions="actionDone"
android:inputType="number"
android:singleLine="true"
android:textColor="#000000"
android:textSize="30dp"
android:textStyle="bold" />
<Button
android:id="#+id/login_button"
style="#style/button_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/username_edtext"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:background="#drawable/button_access"
android:text="Aceptar"
android:textColor="#ffffff" />
<ImageView
android:id="#+id/logo_skilfull"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/logos"
android:scaleType="matrix"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>
<View
android:id="#+id/view2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true" />
<ImageView
android:id="#+id/view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:background="#drawable/member_imview" />
</RelativeLayout>
You should read about the ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
This is a problem changing the size of the View. You need to set scaleType.
Try fitStart.
<ImageView
android:id="#+id/logo_skilfull"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/logos"
android:scaleType="fitStart"
android:layout_alignParentBottom="true" />