I am using a grid view. It shows issue in some devices. One item of the grid view looks shorter in height than others.
It looks like this in some devices, and in some its fine.
Layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:background="#android:color/white"
android:layout_height="match_parent">
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.admin.fueloneApp.MainDriver"
tools:showIn="#layout/app_bar_main"
android:weightSum="8">
<TextView
android:id="#+id/main_welcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/dimen_20dp"
android:text="#string/welcome"
android:textColor="#color/colorPrimary"
android:textStyle="bold" />
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridviewMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/dimen_40dp"
android:layout_marginLeft="#dimen/dimen_40dp"
android:layout_marginRight="#dimen/dimen_40dp"
android:columnWidth="80dp"
android:horizontalSpacing="#dimen/dimen_10dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"></GridView>
</LinearLayout>
</ScrollView>
<TextView
android:id="#+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="false"
android:text="For Any Queries Related To Mobile App Click On Service Request"
android:textAlignment="center" />
</RelativeLayout>
Item layout
EDIT : Added item layout of the grid view.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/single_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary1"
android:orientation="vertical">
<ImageView
android:id="#+id/gris_img"
android:layout_gravity="center"
android:layout_width="80dp"
android:scaleType="fitXY"
android:layout_height="100dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/grid_cat"
android:textSize="15sp"
android:textColor="#color/divider_color"
android:gravity="center"/>
</LinearLayout>
How can I manage the height of each item? What is the solution for this? Please help. thank you...
Gridview is having a tendency to adjust the height of all element with the tallest element in all. Hence this behaviour you are seeing.You can use StaggeredGridView.
i think your grid layout cell height is wrap_content. this problem same occur with me . change your layout height wrap_content to match_parent.
android:layout_height="match_parent"
for better solution please update your grid view item layout cell here.
Add Textview property :
android:maxLines="1"
android:singleLine="true"
if text not visible single line, you need change textview to autosizing-textview
enter link description here
Related
I want my whole screen to scroll but only my recycler will scroll at the moment. This occurs despite all elements being placed in a linear layout inside a Scroll View.
Any ideas where the error is? Here's the relevant code.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".NoodleDetailActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/noodleImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
app:srcCompat="#mipmap/ic_launcher" />
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_bottom"
android:fontFamily="sans-serif-smallcaps"
android:hapticFeedbackEnabled="false"
android:padding="30dp"
android:text="TextView"
android:textSize="18sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/extras_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="#F2F2F2"
android:padding="0dp" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
This is what it looks visually.
demo appearance
Found out: it seems best practice is to set the recyclerView to be the whole layout and make it contain multiple view types.
I won't be using a nested scroll view.
Can you tell me what am I doing wrong? :)
I want to set gravity for my EditText to center_horizontal, but it doesn't work.
Thanks and have a nice day!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<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">
<EditText
android:id="#+id/something"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="85dp"
android:layout_marginLeft="85dp"
android:layout_marginTop="68dp"
android:layout_marginEnd="85dp"
android:layout_marginRight="85dp"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Something"
android:inputType="textPersonName"
android:backgroundTint="#android:color/holo_green_light"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this code.
I have removed the margin of the edit text and changed the layout_height to match parent.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/something"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="85dp"
android:layout_marginEnd="85dp"
android:backgroundTint="#android:color/holo_green_light"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Something"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</ScrollView>
If your intention is to center the EditText inside LinearLayout
Replace
android:gravity="center_horizontal"
With
android:layout_gravity="center_horizontal"
Also, you should remove your margins so it would be perfectly centered horizontally.
hiii.. i have try your code its work good, set gravity for edittext to set Edittext text in horizontal center and its work fine.
if to try to set edit text view in center horizontal. add gravity ="horizontal_center" in linear layout
see this screen shot :
I am trying to make my layout edge round so I am using card view and
also trying to define my own XML with rounded settings and thus link the XML to the background of the Linear Layout but that is also not working.
I have also attached the picture What I am getting from there but I want White rectangular edges to be gone-
..enter image description here
app:cardCornerRadius="9dp"
but here I am getting rectangular background and I don't understand where that white background come from. So, here's my code-
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="9dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:id="#+id/relative_layout"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="46dp"
android:id="#+id/toolbar"
android:background="#color/fab_background">
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_marginBottom="10dp"
android:layout_width="50dp"
android:layout_height="40dp"
android:src="#drawable/expense"
android:id="#+id/expense_image"/>
<EditText
android:layout_marginLeft="29dp"
android:layout_width="match_parent"
android:layout_toRightOf="#id/expense_image"
android:layout_height="40dp"
android:hint="#string/expense"
android:id="#+id/expense"
android:inputType="number"/>
<ImageView
android:layout_width="50dp"
android:layout_height="40dp"
android:src="#drawable/note"
android:id="#+id/note_image"
android:layout_marginTop="60dp"/>
<EditText
android:layout_marginLeft="29dp"
android:layout_marginTop="20dp"
android:layout_toRightOf="#id/note_image"
android:layout_below="#id/expense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/add_note"
android:id="#+id/add_note"/>
</RelativeLayout>
<Button
android:layout_marginTop="20dp"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_margin="16dp"
android:id="#+id/putOn"
android:layout_below="#id/add_note"
android:text="#string/put_on"
android:background="#android:color/darker_gray"/>
</LinearLayout>
</android.support.v7.widget.CardView>
If you are using CardView as a root for for your alert dialog then do as follows . Let me know if it works .
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
card_view:cardBackgroundColor="#android:color/transparent"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
// Your layout goes here
</LinearLayout>
</android.support.v7.widget.CardView>
If still not work then use card_view:cardPreventCornerOverlap attribute in cardview .
Whereas you can use android.support.v7.app.AppCompatDialog for same appearance without any CardView.
Following code produces the result in the blueprint:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/marker_shape">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/marker_header">
<TextView
android:id="#+id/widget_1_header_from"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"/>
<Button
android:id="#+id/widget_1_refresh"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/quantum_ic_refresh_white_24"/>
</LinearLayout>
<ListView
android:id="#+id/widget_1_list"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:layout_width="match_parent"
android:dividerHeight="0dp"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
As you can see: the TextView gets displayed beneath the Button. They need to go next to each other. How do I fix this?
You have 2 options:
Change your button's height to wrap_content.
or:
change your textview height to match_parent.
I have this 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:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<TextView
android:id="#+id/errorMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/pointsText"
android:visibility="gone"/>
<TextView
android:id="#+id/pointsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/offers_list"
android:text="you have 100 points"
android:visibility="visible"/>
<ListView
android:id="#+id/offers_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:dividerHeight="0dp"
android:divider="#00000000"/>
</RelativeLayout>
Yet I cannot see pointsText in my eclipse graphical previewer.
What am I missing?
You have
android:layout_above="#+id/offers_list"
for your TextView but you don't have any positioning for your ListView. Since RelativeLayouts place their children at the top-left by default, your ListView would be at the top and there would be nowhere above it to place your TextView.
Try removing that property from your TextView and add
android:layout_below="#id/pointsText"
on your ListView.
I just tested this and it does work. I can see the pointsText TextView above the list. So, you will want to do something different with your error TextView or you will quite possibly have the same issue with that when you want to change its visibility.
A bit off-topic
RelativeLayout doesn't have an orientation property so that doesn't do you any good but doesn't do you any real harm either.
When you use relative layouts, layout elements lay upon each other. To prevent that you should place element Relatively to other layouts. make your code like this.
<?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:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<TextView
android:id="#+id/errorMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/pointsText"
android:visibility="gone"/>
<TextView
android:id="#+id/pointsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/offers_list"
android:text="you have 100 points"
android:visibility="visible"
android:layout_below="#+id/errorMsg"/>
<ListView
android:id="#+id/offers_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:dividerHeight="0dp"
android:divider="#00000000"
android:layout_below="#+id/pointsText"/>
</RelativeLayout>
Now you will be able to see your all layouts
try this:
<?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:paddingLeft="8dp"
android:paddingRight="8dp" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/errorMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="#+id/pointsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="you have 100 points"
android:visibility="visible"/>
</LinearLayout>
<ListView
android:id="#+id/offers_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/linearLayout1"
android:divider="#00000000"
android:dividerHeight="0dp"
android:drawSelectorOnTop="false" />
</RelativeLayout>
If this is a fragment inside an activity, you may want to check the nesting of say, the AppBarLayout and the layout into which you add the fragment