java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout : XML - java

I am facing issue in android xml. I get error like above but as per my I have not given Circular dependencies in my xml. I am trying from last 1 hour for fix it but I am not able to complete it. I have used above and below as per requirement. I am attaching my xml here. Let me know if someone can point me where I am wrong. My XML is like below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
tools:context="com.karopass.karoshare.ImageDetails">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_imageDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:theme="#style/AppTheme.AppBarOverlay"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<com.example.utils.ExtendedViewPager
android:id="#+id/view_pager_extended"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/pageNavCount"
android:layout_below="#+id/toolbar_imageDetails"
android:background="#color/image_back"/>
<LinearLayout
android:background="#color/colorPrimary"
android:id="#+id/pageNavCount"
android:orientation="horizontal"
android:layout_above="#+id/devider"
android:layout_width="match_parent"
android:layout_height="20dp">
<RelativeLayout
android:layout_weight="3"
android:id="#+id/new_time_count"
style="#style/SelectableItemBackground"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/txt_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 Month ago"
android:textSize="12sp"
android:paddingLeft="5sp"
android:layout_centerVertical="true"
android:textColor="#cccccc"
android:gravity="center|start" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:id="#+id/new_share_count"
style="#style/SelectableItemBackground"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/share_count"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999"
android:textSize="12sp"
android:paddingLeft="5sp"
android:layout_centerVertical="true"
android:textColor="#cccccc"
android:gravity="center|start" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
style="#style/SelectableItemBackground"
android:id="#+id/new_save_count"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/like_count"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999"
android:textSize="12sp"
android:paddingLeft="5sp"
android:layout_centerVertical="true"
android:textColor="#cccccc"
android:gravity="center|start" />
</RelativeLayout>
</LinearLayout>
<View
android:id="#+id/devider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/pageNavLayout"
android:background="#ffffff" />
<LinearLayout
android:background="#color/colorPrimary"
android:id="#+id/pageNavLayout"
android:orientation="horizontal"
android:layout_above="#+id/ll_adLayout_latest"
android:layout_width="match_parent"
android:layout_height="48dp">
<RelativeLayout
android:layout_weight="1"
android:id="#+id/new_time"
style="#style/SelectableItemBackground"
android:clickable="true"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:scaleType="fitCenter"
android:src="#mipmap/ic_past_961"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size" />
</RelativeLayout>-->
<TextView
android:background="#ffffff"
android:layout_width="1dp"
android:layout_height="match_parent" />
<RelativeLayout
android:id="#+id/new_copy"
android:clickable="true"
style="#style/SelectableItemBackground"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="#mipmap/ic_copy_96"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size" />
</RelativeLayout>
<TextView
android:background="#ffffff"
android:layout_width="1dp"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_weight="1"
android:id="#+id/new_save"
style="#style/SelectableItemBackground"
android:clickable="true"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="#mipmap/ic_save_96"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size" />
</RelativeLayout>
<TextView
android:background="#ffffff"
android:layout_width="1dp"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_weight="1"
android:id="#+id/new_share"
style="#style/SelectableItemBackground"
android:clickable="true"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="#mipmap/ic_share_96"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size" />
</RelativeLayout>
<TextView
android:background="#ffffff"
android:layout_width="1dp"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_weight="1"
style="#style/SelectableItemBackground"
android:clickable="true"
android:id="#+id/new_fav"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="#mipmap/ic_hearts_96"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_adLayout_latest"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
Thanks a lot :)

You are using circular dependency here :
<LinearLayout
android:background="#color/colorPrimary"
android:id="#+id/pageNavCount"
android:orientation="horizontal"
android:layout_above="#+id/devider"
android:layout_width="match_parent"
android:layout_height="20dp">
and
<View
android:id="#+id/devider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/pageNavLayout"
android:background="#ffffff" />

you are putting layout_above and layout_below both to the extended view pager put only above or below and try it will solve let me know if its get solved

Related

I'm making a mistake somewhere while making a simple design

no matter what I do in my design, I want to center what I wrote with the photographs, but I cannot do the design, I wonder where I am going wrong I'm learning new and tried to make a design like in the photo
I'll create the rest using the recycler view and card view
Enough explanation, I hope I don't want to confuse you
<androidx.cardview.widget.CardView 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:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView6"
android:layout_width="60dp"
android:layout_height="60dp"
android:contentDescription="TODO" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Date" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView7"
android:layout_width="60dp"
android:layout_height="60dp"" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
Splitted the center part to two linear layouts. Also added android:gravity="center|bottom" to the TextView which contains the date.
<androidx.cardview.widget.CardView 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:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView6"
android:layout_width="60dp"
android:layout_height="60dp"
android:contentDescription="TODO" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="text" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="text" />
</LinearLayout>
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|bottom"
android:text="Date" />
</LinearLayout>
<ImageView
android:id="#+id/imageView7"
android:layout_width="60dp"
android:layout_height="60dp" />
</LinearLayout> </androidx.cardview.widget.CardView>
Here's how it looks like. I added some colors so it's easier to see where layouts begin and end. The colors are not part of the xml.

Automatic scrolling when the keyboard is opened

I want the screen to automatically scroll up when the keyboard opens, so that the user can see what he has written.
The solution I found was to change the manifest and use adjustPan or adjustResize. I used both of them but it still didn't work.
Where is my mistake?
Thanks in advance.
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context=".auth.LoginActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="#mipmap/img_login"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
tools:ignore="MissingConstraints" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-100dp"
android:orientation="vertical"
android:background="#drawable/login_back">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:textColor="#color/customColor"
android:gravity="center"
android:textSize="30dp"
android:layout_marginTop="42dp"/>
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:focusableInTouchMode="true"
android:hint="User Name"
android:layoutDirection="rtl"
android:textColorHint="#color/customColor"
>
<EditText
android:id="#+id/acLogin_edtUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="ltr"
android:inputType="textEmailAddress"
android:textSize="16dp"
android:singleLine="true"
android:textColor="#color/customColor"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:focusableInTouchMode="true"
android:hint="Password"
android:layoutDirection="rtl"
android:textColorHint="#color/customColor"
>
<EditText
android:id="#+id/acLogin_edtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textSize="16dp"
android:textColor="#color/customColor"
/>
</com.google.android.material.textfield.TextInputLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="42dp"
android:layout_gravity="center"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:clickable="true"
android:focusable="true"
app:cardBackgroundColor="#color/customColor"
app:cardCornerRadius="8dp">
<TextView
android:id="#+id/acLogin_txtLogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Login"
android:textColor="#ffffff"
android:textSize="18dp" />
<ProgressBar
android:id="#+id/acLogin_prgLoading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:visibility="gone" />
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="48dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Don't have any account?"
android:gravity="bottom"
android:layout_marginLeft="58dp"
android:textColor="#color/customColor"
android:textSize="16dp"/>
<TextView
android:id="#+id/acLogin_txtSignUp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:gravity="bottom"
android:text="Sign Up"
android:textColor="#color/customColor"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="200dp"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I change manifest to:
<activity android:name=".auth.LoginActivity"
android:windowSoftInputMode="adjustPan | adjustResize"/>

Android: How to get the Calendar in YEAR/MONTH/DATE Spinners

In my Android app, I am trying to get the birthday of the user. Below is my XML document .
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/colorPurple"
app:popupTheme="#style/AppTheme.PopupOverlay"
style="#style/MyDrawerArrowToggle"
android:layout_marginTop="#dimen/toolbar_layout_top_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#+id/signUp_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/back_arrow_white" />
</LinearLayout>
<LinearLayout
android:layout_width="220dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20dp"
android:text="#string/birthday"
android:textColor="#color/colorWhite"
android:gravity="center|left"
android:paddingLeft="20dp"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textStyle="bold"
android:text="#string/what_is_your_birthday"
android:gravity="center"
android:layout_marginTop="60dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="30dp">
<DatePicker
android:layout_width="match_parent"
android:layout_height="150dp"
android:datePickerMode="spinner"
android:id="#+id/date_picker"/>
<!--<com.aigestudio.wheelpicker.widgets.WheelDayPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent" />-->
<!--<com.aigestudio.wheelpicker.widgets.WheelMonthPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginLeft="20dp"/>-->
<!--<com.aigestudio.wheelpicker.widgets.WheelYearPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginLeft="20dp"/>-->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/colorPurple"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="#+id/signup_birthday_next_button_layout">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text = "#string/next_text"
android:textColor="#color/colorWhite"
android:textSize="14dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
This gives me the below UI
But I am looking for the below
How can I get the second UI?
Please add this xml file it may be help full to solve your problem.
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:gravity="center"
android:id="#+id/btnNotification"
android:text="What is your birthday"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<DatePicker
android:id="#+id/spinnerDatePicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:spinnersShown="true" />
<Button
android:text="next"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
You can use SpinnerDatePicker open source library it has UI like below
As it is open source you can change if you need.

Views shrink when using keyboard with PercentageLayout

i have 2 different XML files. One is signup.xml the other chat.xml, both constructed with the PercentageLayout library.
the signup.xml works great - opening keyboard doesnt change any view.
However, in chat.xml whenever i pop the keyboard the view shrinks or out of screen, and i dont know why since i constructed them both nearly in the same manner, only i suspect that because i use ScrollView this happens.
The problematic layout, chat.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- top -->
<LinearLayout
android:id="#+id/top"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
android:background="#075607"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#acddf4"
android:textSize="20sp"
android:text="jfioewjfoiewjfoi"
android:gravity="center"
android:layout_gravity="center_horizontal|center_vertical" />
</LinearLayout>
<!-- Mid -->
<LinearLayout
android:id="#+id/mid"
android:layout_below="#+id/top"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="84%"
android:background="#b1b7b3"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroller"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#drawable/chat_bg" >
<LinearLayout
android:id="#+id/chatWindowContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
<!-- Bottom -->
<LinearLayout
android:id="#+id/bottom"
android:layout_below="#+id/mid"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
android:background="#000000"
android:orientation="horizontal">
<EditText
android:id="#+id/etMessage"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:paddingLeft="5dp"
android:background="#drawable/text"
android:imeOptions="actionNone"
android:inputType="textMultiLine"
android:singleLine="false" />
<Button
android:id="#+id/bSendMessage"
android:layout_width="40dp"
android:layout_height="match_parent"
android:background="#drawable/ic_send"
android:layout_gravity="right" />
</LinearLayout>
And the working layout, signup.xml :
<LinearLayout
android:id="#+id/title"
android:layout_height="0dp"
android:layout_width="0dp"
app:layout_heightPercent="15%"
app:layout_widthPercent="100%">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/signup"/>
</LinearLayout>
<LinearLayout
android:id="#+id/mid"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_below="#+id/title"
app:layout_heightPercent="35%"
app:layout_widthPercent="100%"
android:baselineAligned="true">
<!-- Username -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="#drawable/person" />
<EditText
android:id="#+id/etUsername_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="text"
android:text="test"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="#drawable/text">
<requestFocus />
</EditText>
</LinearLayout>
<!-- Email -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="#drawable/email" />
<EditText
android:id="#+id/etEmail_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textEmailAddress"
android:text="email#address.com"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="#drawable/text"/>
</LinearLayout>
<!-- Password1 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="#drawable/password" />
<EditText
android:id="#+id/etPassword1_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textPassword"
android:text="pass"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="#drawable/text"/>
</LinearLayout>
<!-- Password2 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="#drawable/password" />
<EditText
android:id="#+id/etPassword2_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textPassword"
android:text="pass"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="#drawable/text"/>
</LinearLayout>
<!-- Spinner and RadioGroup-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Spinner
android:layout_width="100dp"
android:layout_height="match_parent"
android:id="#+id/spinner"
android:layout_gravity="center" />
<RadioGroup
android:id="#+id/rgRadius"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Kilometer" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mile" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
<!-- Image -->
<LinearLayout
android:id="#+id/image"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_below="#+id/mid"
app:layout_heightPercent="40%"
app:layout_widthPercent="100%"
android:baselineAligned="true">
<ImageView
android:id="#+id/imgProfile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/faceless" />
</LinearLayout>
<!-- Button -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="10%"
app:layout_widthPercent="100%"
android:orientation="vertical"
android:layout_below="#id/image">
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="#+id/bSignup"
android:layout_gravity="center|bottom"
android:background="#drawable/button_send" />
</LinearLayout>
Use relative layout solve your shrinking layout problem I tested following layout.
Add following entry with activity tag : android:windowSoftInputMode="adjustResize"
And Your layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- top -->
<LinearLayout
android:id="#+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#075607"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#acddf4"
android:textSize="20sp"
android:text="jfioewjfoiewjfoi"
android:gravity="center"
android:layout_gravity="center_horizontal|center_vertical" />
</LinearLayout>
<!-- Mid -->
<LinearLayout
android:id="#+id/mid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom"
android:layout_below="#+id/top"
android:background="#b1b7b3"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroller"
android:layout_width="match_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/chatWindowContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
<!-- Bottom -->
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/etMessage"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:paddingLeft="5dp"
android:imeOptions="actionNone"
android:inputType="textMultiLine"
android:singleLine="false" />
<Button
android:id="#+id/bSendMessage"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_gravity="right" />
</LinearLayout>
</RelativeLayout>

Android layout inconsistency

I have a layout that is being displayed in two different layouts. First one is being displayed in a LinearLayout and it behaves as expected:
However, when this layout is part of a listview, the textview is not centered:
Here's 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="130dp"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:padding="5dp">
<com.parse.ParseImageView
android:id="#+id/iv"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitCenter"/>
<TextView
android:id="#+id/tv_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.5"
android:layout_marginLeft="10dp"
android:textAppearance="#android:style/TextAppearance.Holo.Medium"
android:ellipsize="end"
android:maxLines="3"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:orientation="horizontal"
android:paddingLeft="10dp">
<View
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/blue"
android:layout_gravity="center"
/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<TextView
android:id="#+id/tv_source"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAppearance="#android:style/TextAppearance.Holo.Small"
android:gravity="center"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="sans-serif-light"
android:textAppearance="#android:style/TextAppearance.Small"
android:gravity="center"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_fire"
android:layout_gravity="center"/>
<TextView
android:id="#+id/tv_viewCount"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="sans-serif-light"
android:textAppearance="#android:style/TextAppearance.Small"
android:gravity="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"/>
</LinearLayout>
<ImageView
android:id="#+id/pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_pin"/>
<TextView
android:id="#+id/comment_tv"
android:layout_width="0dp"
android:layout_height="0dp"
android:textColor="#color/white"
android:layout_alignTop="#+id/pin"
android:layout_alignBottom="#+id/pin"
android:layout_alignLeft="#id/pin"
android:layout_alignRight="#+id/pin"
android:gravity="center"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
The textView that I am referring to is at the bottom with id comment_tv
What am I doing wrong?
Thanks
Your pin+text inside a relative layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_gravity="center_vertical" >
<ImageView
android:id="#+id/pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_pin"/>
<TextView
android:id="#+id/comment_tv"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#id/pin"
android:gravity="center"
android:layout_marginTop="10dp" //set this higher if you need
android:layout_centerHorizontal="true" //if this text will be not in the center
//you can use the "layout_marginLeft" to put whatever you want
/>
</RelativeLayout>
This should but the text on the spot you want
I tried it with your image and this is my result with underlying code. Is this what you are looking for?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/sample"
android:gravity="center"
android:text="12"
android:textSize="18sp" />
</LinearLayout>
And heres a snapshot of this code:

Categories