Cant remove admob from scrollview - java

Ive got this project and ive put admob on it but the ad must always be on the bottom of the screen and when you scroll up and down the page the ad must stay in the same place.
It seems ive done something wrong somewhere as the ad has its own little scroll view layout? Ive put a screen shot below along with the code for the layout
edited homexml code but with error
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/ScrlView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
android:layout_weight="1">
<ScrollView
android:id="#+id/ScrlView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/MainActivity"
android:layout_marginBottom="20dp" >
<LinearLayout
android:id="#+id/layoutForScroll"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:gravity="center"
android:text="Welcome To Ride Count!"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#1E90FF"
android:textStyle="bold" >
</TextView>
<RelativeLayout
android:id="#+id/layoutTextViews_one"
android:layout_width="280dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/smallbox1" >
<TextView
android:id="#+id/txtCountLabel_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="Rides Ridden:"
android:textColor="#1E90FF"
android:textStyle="bold" >
</TextView>
<TextView android:textStyle="bold" android:gravity="center" android:text="0000" android:layout_height="wrap_content"
android:layout_width="match_parent" android:id="#+id/sum"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" android:layout_marginTop="45dp"></TextView>
</RelativeLayout>
<TextView
android:id="#+id/txtFact"
android:layout_width="280dp"
android:layout_height="180dp"
android:layout_gravity="center"
android:layout_marginTop="23dp"
android:background="#drawable/factbox"
android:gravity="center"
android:text="Tap For Fact"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/MainActivity"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="0dp"
android:layout_weight="2">
</LinearLayout>
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
googleads:adSize="SMART_BANNER"
googleads:adUnitId="#string/admob_id" />
</LinearLayout>
ad mob layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ad_catalog_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/banner_bottom" />
<TextView android:id="#+id/status"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:text="" />
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="60dp"
googleads:adSize="IAB_MRECT"
googleads:adUnitId="#string/admob_id" />
</LinearLayout>
home XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundtowers"
android:orientation="vertical"
android:scrollbars="vertical"
android:weightSum="1" >
<ScrollView
android:id="#+id/ScrlView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/MainActivity"
android:layout_marginBottom="20dp" >
<LinearLayout
android:id="#+id/layoutForScroll"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:gravity="center"
android:text="Welcome To Ride Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#1E90FF"
android:textStyle="bold" >
</TextView>
<RelativeLayout
android:id="#+id/layoutTextViews_one"
android:layout_width="280dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/smallbox1" >
<TextView
android:id="#+id/txtCountLabel_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="Rides Ridden:"
android:textColor="#1E90FF"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/sum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:gravity="center"
android:text="0000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
<TextView
android:id="#+id/txtFact"
android:layout_width="280dp"
android:layout_height="180dp"
android:layout_gravity="center"
android:layout_marginTop="23dp"
android:background="#drawable/factbox"
android:gravity="center"
android:text="Tap For Fact"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/MainActivity"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp" >
</LinearLayout>
</RelativeLayout>

Change the layout_height and layout_width to wrap_content of your ad to see if that removes it. You may also want to try using the SMART_BANNER option in asSize to adjust for size automatically.
The SMART_BANNER option was added in AdMob version 6.0. Take a look at https://developers.google.com/mobile-ads-sdk/docs/admob/smart-banners. It's way easier to work with.
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
googleads:adSize="SMART_BANNER"
googleads:adUnitId="#string/admob_id" />
I'd use a LinearLayout since it's a bit easier in this case, but you can still use a RelativeLayout if you prefer them. The idea is to put the AdView in the XML and use layout_weight to the rest of your layout to fill the View.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/ScrlView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
android:layout_weight="1">
<!-- ... -->
</ScrollView>
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
googleads:adSize="SMART_BANNER"
googleads:adUnitId="#string/admob_id" />
</LinearLayout>

ScrollView and your AdView need to be peers in your RelativeLayout. I have implemented exactly what you desire in this way.
RelativeLayout
ScrollView
LinearLayout
AdView

Related

admob banner not showing in LinearLayout

hello AdMob banner ads not showing up any more after I add ScrollView I don't know why I tried many time but nothing
before added ScrollView is was working well
I have tried many methods to put in bottom the layout but not working with me
plz if you can help me I want to I want to place the ad on the bottom I have a LinearLayout. When I do it never shows up
<Toolbar
android:id="#+id/mytoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</Toolbar>
<ScrollView
android:layout_above="#+id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:gravity="center_vertical"
android:background="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15.0dip">
<TextView
android:textSize="17.0sp"
android:textColor="#ff000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Extreme power saving mode" />
</LinearLayout>
<Switch
android:id="#+id/setSwitch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10.0dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/ad_banner">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</LinearLayout>
I looked into your code. Wrap your layout in relative. Layout below and above only works in relative not in linear, and remove the two linear layout below that is wrapping the adView.
This should work
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:orientation="vertical"
android:background="#fff1f1f1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto">
<Toolbar
android:id="#+id/mytoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</Toolbar>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/mytoolbar"
android:layout_above="#+id/adView">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:gravity="center_vertical"
android:background="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15.0dip">
<TextView
android:textSize="17.0sp"
android:textColor="#ff000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Extreme power saving mode" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3.0dip"
android:text="The disadvantage is that the playback progress will be lost."
android:ems="11" />
</LinearLayout>
<Switch
android:id="#+id/setSwitch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10.0dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<RelativeLayout
android:background="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15.0dip">
<TextView android:textSize="17.0sp"
android:textColor="#ff000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Desktop control playback" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3.0dip"
android:text="Quickly click or swipe three times" />
</LinearLayout>
<Switch android:id="#+id/setSwitch2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10.0dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<RelativeLayout
android:background="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip">
<TextView
android:textSize="17.0sp"
android:textColor="#ff000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15.0dip"
android:text="Sound" />
<Switch
android:id="#+id/setSwitch3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10.0dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/setRelativeLayout1"
android:background="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15.0dip">
<TextView
android:textSize="17.0sp"
android:textColor="#ff000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Compatibility mode" />
<TextView
android:id="#+id/moreTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3.0dip"
android:text="MIUI8 set as lock screen wallpaper" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/setRelativeLayout2"
android:background="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip">
<TextView
android:textSize="17.0sp"
android:textColor="#ff000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15.0dip"
android:text="Get Starry Sky Wallpaper" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlRate"
android:background="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip">
<TextView android:textSize="17.0sp"
android:textColor="#ff000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15.0dip"
android:text="rate us " />
</RelativeLayout>
<RelativeLayout android:id="#+id/setRelativeLayout3"
android:background="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip">
<TextView android:textSize="17.0sp"
android:textColor="#ff000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15.0dip"
android:text="Close wallpaper" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/ad_banner">
</com.google.android.gms.ads.AdView>
</RelativeLayout>

Imageview not taking corner radius of cardview

Hi i'm developing an app where i'm using imageview inside cardview but my problem is that imageview somehow is not taking the corner radius applied to cardview
Please see the image below
I tried doing different things but dont understand where the problem is please if anyone can guide 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"
xmlns:card_view="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:id="#+id/cardview2"
app:cardCornerRadius="25dp"
card_view:cardPreventCornerOverlap="false"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:layout_width="88dp"
android:layout_height="88dp"
android:id="#+id/imageView"
android:scaleX="1.2"
android:scaleType="fitXY"
android:scaleY="1.2"
android:src="#drawable/club1"
android:background="#drawable/corner_radius"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="#+id/nameTextView"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="16dp"
android:maxLines="2"
android:text="Item"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:id="#+id/ratingTextView"
android:layout_marginStart="4dp"
android:drawableEnd="#color/White"
android:drawableRight="#color/White"
android:drawablePadding="2dp"
android:text="4,5"
android:gravity="center"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="12sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
See here is the Image. Remeber Don't make CardView as Main 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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
app:cardUseCompatPadding="true"
android:elevation="0dp"
app:cardCornerRadius="5dp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_suvichar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/placeholder" />
<TextView
android:id="#+id/tv_suvichar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Title"
android:padding="5dp"
android:textColor="#color/black"
android:textSize="#dimen/normal_text_size" />
</LinearLayout>
</android.support.v7.widget.CardView>
Try Replace your Linear Layout with Relative Layout.
After that set gravity of your last textview (center_horizontal).
You can use the RoundedImageView :
Put this in the build.gradle
compile 'com.makeramen:roundedimageview:2.3.0'
And to use it:
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
app:riv_corner_radius="5dp"/>
Just use this code in xml and see result after RUN the code:
<android.support.v7.widget.CardView
android:layout_marginTop="100dp"
android:layout_gravity="center_horizontal"
app:cardCornerRadius="20dp"
android:id="#+id/cv"
android:clipChildren="true"
android:layout_width="100dp"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:scaleType="centerCrop"
android:src="#drawable/recipe"
android:layout_width="match_parent"
android:layout_height="100dp" />
<TextView
android:layout_margin="8dp"
android:text="ITEM"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginLeft="8dp"
android:layout_marginBottom="8dp"
android:text="34"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
Try this way :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/_5sdp"
android:layout_marginTop="#dimen/_5sdp"
android:layout_marginLeft="#dimen/_5sdp"
android:layout_marginRight="#dimen/_5sdp"
android:layout_marginBottom="5dp"
cardview:cardCornerRadius="#dimen/_3sdp"
cardview:cardElevation="#dimen/_3sdp"
cardview:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="#dimen/_180sdp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/placeholder"/>
<RelativeLayout
android:padding="#dimen/_5sdp"
android:id="#+id/rlMiddle"
android:layout_below="#+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtPrescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_10sdp"
android:maxLines="3"
android:paddingTop="8dp"
android:textAppearance="#style/TextAppearance.AppCompat.Headline"
android:textSize="#dimen/_16sdp"
android:text="Demo"
android:textStyle="bold"
/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>

Stick header at top when Softkeyboard is opened android

I have a layout, in which I need that the top header should should not hide when I open softKeyBoard. I am using Fragment here.I am using recylerView.
when i am opening softkeyboard the top header is scrolling up. I need that header to stay there and Recyclerview to scroll.
Below is my xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rel_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bggradient">
<RelativeLayout
android:id="#+id/rel_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#drawable/drawable_below_line">
<ImageView
android:id="#+id/iv_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/txtSettingHeader"
android:layout_alignTop="#+id/txtSettingHeader"
android:layout_centerVertical="true"
android:background="#drawable/button_selector"
android:onClick="onClickEvent"
android:padding="10dp"
android:src="#mipmap/ic_back" />
<TextView
android:id="#+id/txtUserName"
style="#style/FragHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<ImageView
android:id="#+id/iv_userImage"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/txtUserName"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/txtUserName"
android:layout_centerVertical="true"
android:onClick="onViewClick"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:src="#mipmap/ic_male" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/lin_comment"
android:layout_below="#+id/rel_header"
android:gravity="top"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyelerViewChat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
</android.support.v7.widget.RecyclerView>
<TextView
android:id="#+id/tv_txtNoRecords"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:minHeight="100dp"
android:text="#string/txtNoChat"
android:textColor="#android:color/white"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="#+id/lin_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#70FFFFFF"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<LinearLayout
android:id="#+id/linEditComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<ImageView
android:id="#+id/iv_imgToggleKeyboardEmoji"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:src="#mipmap/ic_emoji" />
<com.lawo.emojicon.EmojiconEditText
android:id="#+id/et_edtChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/drawable_black_border"
android:hint="#string/hintTypeMessage"
android:inputType="textNoSuggestions|textMultiLine"
android:maxLength="500"
android:maxLines="3"
android:padding="10dp"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray" />
</LinearLayout>
<ImageView
android:id="#+id/iv_imgSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="onClickEvent"
android:padding="10dp"
android:src="#mipmap/ic_sent" />
</LinearLayout>
</RelativeLayout>
Add the following to your "activity" tag in AndroidManifest.xml:
android:windowSoftInputMode="adjustResize"
Reference: Specify How Your UI Should Respond.

How to align title,description and url in equal space

Here is a screenshot of layout as it currently appears on my screen:
Here is the xml code snippet for the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/icon"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_alignParentRight="true"
android:layout_marginRight="-10dp" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="20dp"
android:fontFamily="Cabin-Regular"
android:paddingLeft="10dp"
android:textColor="#E35B5B"
android:textSize="14dp" />
<TextView
android:id="#+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:height="44dp"
android:fontFamily="Cabin-Regular"
android:paddingLeft="10dp"
android:paddingRight="100dp"
android:textColor="#2D2D2D"
android:textSize="16dp" />
<TextView
android:id="#+id/url_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_marginTop="50dp"
android:height="15dp"
android:paddingLeft="10dp"
android:paddingRight="80dp"
android:textColor="#BDBDBD"
android:textSize="10dp" />
</RelativeLayout>
Just want to have the three textviews properly aligned and have equal space among each other.
Here is your layout,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/icon"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_alignParentRight="true"
android:layout_marginRight="-10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="110dp"
android:layout_toLeftOf="#+id/icon"
android:orientation="vertical"
android:weightSum="3">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fontFamily="Cabin-Regular"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Title"
android:textColor="#E35B5B"
android:textSize="14dp" />
<TextView
android:id="#+id/desc"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/title"
android:layout_weight="1"
android:fontFamily="Cabin-Regular"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Description"
android:textColor="#2D2D2D"
android:textSize="16dp" />
<TextView
android:id="#+id/url_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/title"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="URL"
android:textColor="#BDBDBD"
android:textSize="10dp" />
</LinearLayout>
</RelativeLayout>
Pawan Thakur Use the same paddingLeft for all test and layoutBelow like below
<TextView
android:id="#+id/url_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/desc"
android:height="15dp"
android:paddingRight="80dp"
android:paddingLeft="10dp"
android:text="url"
android:textColor="#BDBDBD"
android:textSize="10dp" />
here is the code. Try maximum to use LinearLayout instead of Relative. Relative layout are used in cases where 2 or more elements have to be overlapped each other. Don't include every elements in a single layout. Divide your design into different sections, and use LinearLayout for each section and within each section, include elements belonging to that section.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".25"
android:orientation="vertical"
>
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#E35B5B"
android:fontFamily="Cabin-Regular"
android:textSize="14dp"
android:layout_weight="0.33"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center|left"
android:paddingLeft="10dp"
android:text="Google"
/>
<TextView
android:id="#+id/desc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#2D2D2D"
android:fontFamily="Cabin-Regular"
android:textSize="16dp"
android:layout_weight="0.33"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center|left"
android:paddingLeft="10dp"
android:text="Google is a Search engine"
/>
<TextView
android:id="#+id/url_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/title"
android:textColor="#BDBDBD"
android:textSize="10dp"
android:layout_weight="0.33"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center|left"
android:paddingLeft="10dp"
android:text="http://www.google.com"
/>
</LinearLayout>
<LinearLayout
android:layout_width="110dp"
android:layout_height="110dp"
>
<ImageView
android:id="#+id/icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
u can use a android:weight="" to child of relative layout
Create LinearLayout for title, description and url with vertical orientation and weightsum=3 in Layout and for each of them use width=wrap_content, height=0dp, weight=1.
Okey.. First remove android:height from each TextView and in last TextView you have set android:layout_marginTop="50 remove it.
Tip : Use LinearLayout if your want to show your all view vertically or horizontally. if you want to use RelativeLayout make sure you give margin and padding properly so they look good.
Use Linear layout as parent with weightsum and equally distribute weight amongs the child layouts. ex : If android:weightsum = "3" for parent then android:layout_weight = "1" for each child layout(if you want equal space for each one of the 3 child).
ps: dont forget to mention orientation for Linearlayout.
Just Check this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1
android:padding="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#E35B5B"
android:fontFamily="Cabin-Regular"
android:textSize="14dp"
android:text="Google"/>
<TextView
android:id="#+id/desc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#2D2D2D"
android:fontFamily="Cabin-Regular"
android:textSize="16dp"
android:margin_top="5dp"
android:text="Google is a Search engine"/>
<TextView
android:id="#+id/url_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#BDBDBD"
android:textSize="10dp"
android:margin_top="5dp"
android:text="http://www.google.com"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"/>
</LinearLayout>
</LinearLayout>

Android LinearLayout place elements in the middle with landscape and portrait mode

My layout contains three buttons, one EditText field and one button. I want to place the three buttons in one row, but in the center (horizontal) of the screen. The EditText field should be below the buttons and below the EditText field, there should be one button.
Here is my layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blueAct"
android:orientation="vertical"
android:paddingBottom="100.0dip"
android:paddingLeft="10.0dip"
android:paddingRight="10.0dip"
android:paddingTop="100.0dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="4.0dip"
android:paddingLeft="100.0dip"
android:paddingRight="100.0dip"
android:paddingTop="5.0dip" >
<ImageButton
android:id="#+id/buttonGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="4.0dip"
android:background="#drawable/green_button"
android:contentDescription="#string/green" />
<ImageButton
android:id="#+id/buttonRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="4.0dip"
android:background="#drawable/red_button"
android:contentDescription="#string/red" />
<ImageButton
android:id="#+id/buttonBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="4.0dip"
android:background="#drawable/blue_button"
android:contentDescription="#string/blue" />
</LinearLayout>
<EditText
android:id="#+id/phone_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/phone_code"
android:paddingTop="100.0dip"
android:textColor="#color/white"
android:textColorHint="#color/white" >
<requestFocus />
</EditText>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#color/orangeAct"
android:onClick="searchUsers"
android:paddingTop="100.0dip"
android:text="#string/button_go"
android:textColor="#color/white" />
</LinearLayout>
Now the problem is, that the three buttons are not in the center if the user changes from portrait to landscape mode.
How is it possible to make this 'responsive', without creating a separate layout file for landscape mode?
Any help would be greatly appreciated.
Don't use padding on your horizontal LinearLayout to center the views. Instead you can add views before and after that expand to fill the remaining space.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:id="#+id/buttonGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<ImageButton
android:id="#+id/buttonRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<ImageButton
android:id="#+id/buttonBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#mipmap/background"
android:orientation="vertical"
android:id="#+id/homemain124"
android:weightSum="3">
<RelativeLayout
android:id="#+id/paneltamrin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="something"
android:textColor="#fff"
android:id="#+id/top1"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp"
android:padding="8dp"
android:background="#drawable/textcorner"
android:layout_below="#+id/top1"
android:text="something"
android:textSize="20sp"
android:textColor="#fff"
android:id="#+id/top2"
android:fontFamily="monospace"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_marginTop="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/top2"
android:text="APPLIED BY"
android:textSize="15sp"
android:id="#+id/top3"
android:textColor="#fff"
android:gravity="center_horizontal"
android:layout_marginTop="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/top3"
android:text="COURT OF JUSTICE IN INDIA"
android:id="#+id/top4"
android:textSize="15sp"
android:textColor="#fff"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/paneltamrin2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="220dp"
android:layout_height="160dp"
android:src="#mipmap/book1"
android:id="#+id/image1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/paneltamrin3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="READ NOW"
android:textColor="#fff"
android:lineSpacingExtra="10dp"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="15dp"
android:id="#+id/buttonorder"
android:padding="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/orderbutton"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="13sp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:layout_below="#+id/buttonorder"
android:text="something"/>
</RelativeLayout>
</LinearLayout>
Linear layout added for 3 relative layouts

Categories

Resources