why am not able to view to complete text in my app - android

<?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"
android:background="#F3E889"
android:paddingLeft="100dp"
android:paddingTop="100dp"
android:paddingEnd="100dp"
android:paddingRight="100dp"
android:paddingBottom="100dp"
android:textAlignment="center"
android:visibility="visible"
tools:context=".MainActivity">
<EditText
android:id="#+id/editTextTextPersonName4"
android:layout_width="300dp"
android:layout_height="300dp"
android:ems="100"
android:inputType="textPersonName"
android:text="I want to be a Android developer"
tools:layout_editor_absoluteX="-64dp"
tools:layout_editor_absoluteY="-46dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is simple code which is trying to print I want to be a Android developed but when viewed on
mobile its not showing the complete sentence.

May be you don't give a proper constraints to your editText also you don't give a proper padding to your parent layout, please try this code :
<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"
android:background="#F3E889"
android:padding="10dp"
android:textAlignment="center"
android:visibility="visible"
tools:context=".MainActivity">
<EditText
android:id="#+id/editTextTextPersonName4"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:inputType="textPersonName"
android:text="I want to be a Android developer"/>

There's 100 dp of padding on all 4 sides. That pushes all the content to the middle of the screen. It cuts off like half of the usable space.

Related

LinearLayout elements sizes XML

I can make something like this in my layout but I want to put the ok button at right.
But when I try to make this I have this instead of.
here is my code(second image).
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#00cc33"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:background="#0033cc"
android:layout_width="fill_parent"
android:layout_height="95dip"
android:orientation="horizontal">
<EditText
android:text="Enter text"
android:layout_width="match_parent"
android:layout_height="95dip"/>
<Button
android:text="OK"
android:layout_height="95dip"
android:layout_width="95dip"/>
</LinearLayout>
</LinearLayout>
I hope it's possible to make this using only XML?
Maybe, you need to use RelativeLayoutand specify attributes related to disposition of elements. Try to check here: https://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams
I think the constraint layout is the best if you use xml.
The 0 dp with constraints can help a lot
<?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=".MainActivity">
<Button
android:id="#+id/button"
android:layout_width="95dp"
android:layout_height="95dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Ok" />
<EditText
android:id="#+id/editTextTextPersonName"
android:layout_width="0dp"
android:layout_height="0dp"
android:ems="10"
app:layout_constraintTop_toTopOf="#id/button"
app:layout_constraintStart_toEndOf="#id/button"
app:layout_constraintBottom_toBottomOf="#id/button"
app:layout_constraintEnd_toEndOf="parent"
android:inputType="textPersonName"
android:text="Name" />
</androidx.constraintlayout.widget.ConstraintLayout>

Add animation for Changing Height of Layout

I have a small view, which at the beginning only contains a loading indicator, which is why it is relatively small. However, when the actual content is loaded, I would like to display that instead of the loading indicator, for which I add 2 text fields and an ImageView. Currently I just do this by hiding the ProgressBar and showing the elements I just mentioned, but this way there is a hard cut between the two states. I would like to change this so that first the height of the view is adjusted over a short period of time, and then the content is shown (maby faded in, but I'm more concerned about changing the height).
In general I already have some ideas how to do this, but I don't know how to calculate the new height? Is there a way to calculate it, or even a function directly from Android that solves my Problem?
Thanks already :)^
Heres the Layout for the Fragment:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/home_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".viewables.fragments.home.HomeFragment">
<ListView
android:id="#+id/home_vertretungsplan_preview"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="#layout/vertretungsplan_list_item"/>
<include
android:animateLayoutChanges="true"
android:layout_weight="0"
android:id="#+id/home_article_preview"
layout="#layout/thomsline_main_recyclerview_article"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
</LinearLayout>
and here ist the Included Layout
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
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:animateLayoutChanges="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:clickable="true"
android:focusable="true"
app:cardElevation="10dp"
app:cardCornerRadius="20dp"
app:cardPreventCornerOverlap="false">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/thomsline_post_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="0dp"
android:adjustViewBounds="true"
android:padding="0dp"
android:scaleType="centerCrop"
android:src="#drawable/img_thomsline_article_image_default"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp"
android:id="#+id/container1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/thomsline_post_image"
app:layout_constraintLeft_toLeftOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="19sp"
android:id="#+id/thomsline_post_title"
tools:text="Article Title"/>
<TextView
android:id="#+id/thomsline_post_excerpt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textAllCaps="false"
android:textSize="12.5sp"
tools:text="Post Excerpt" />
</LinearLayout>
<ProgressBar
android:id="#+id/thomsline_post_loading_indicator"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="gone"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
You can try using animateLayoutChanges attribute in your parent layout.
Add this line to your root element of your activity layout :
android:animateLayoutChanges="true"
Or you can use TransitionManager for smooth transitions. (API 19+)
Add this code to your file just before the line where you set your content :
TransitionManager.beginDelayedTransition(cardView); //Default transition
You can pass your preferred transition to this function like this :
Transition transition = new ChangeBounds();
TransitionManager.beginDelayedTransition(cardView,transition);
You can choose any transition :
ChangeBounds
Explode
Slide
Fade
AutoTransition
TransitionSet
If you want to know more about animations in android, i would suggest u read this : Simple Animations in Android

Recyclerview gap between item API 19

I'm doing a small application and am using a RecyclerView but when I emulate my application on API 19 I got small gap between the item, however if I run the same application on API 22 there is no gap (there is a screen at the end).
I'm using material design
frag_home
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_videos"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:listitem="#layout/item_video"
/>
</LinearLayout>
item_card
xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
app:cardPreventCornerOverlap="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/video_preview"
android:layout_width="match_parent"
android:layout_height="194dp"
android:scaleType="centerCrop"
tools:src="#drawable/img_error_v1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="#+id/video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceHeadline6"
android:maxLines="1"
tools:text="This is a really really really really really really really really really really really long title"
/>
<TextView
android:id="#+id/video_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary"
tools:text="This is the URL for now"
/>
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
Here is the image, on the left is API 22 and on the right API 19
For my application, I don't need to use CardView therefore I changed them for a LinearLayout.
You can check these post to know more about CardView and layout
Why use a CardView instead of a RelativeLayout or LinearLayout?
Advantage and disadvantage of CardView

First letter input in EditText is not fully visible when using a custom font in Android

I can't seem to make my first letters show correctly when using a custom font with EditText in Android Studio
<?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"
tools:context=".MainActivity">
<EditText
android:id="#+id/editText"
android:paddingLeft="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:fontFamily="#font/telly_humble"
android:textSize="35dp"
android:text="jay" />
</RelativeLayout>
Edit: forgot to mention that I also tried padding-left or start, neither worked for me.
My final solution would be to change the font.
Try to add paddingLeft.
<?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"
tools:context=".MainActivity">
<EditText
android:id="#+id/editText"
android:layout_marginLeft="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:fontFamily="#font/telly_humble"
android:paddingLeft="10dp"
android:textSize="35dp"
android:text="jay" />
</RelativeLayout>
Add padding on the left and Right side it should solve the issue
<EditText
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:id="#+id/editText"
android:layout_marginLeft="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:fontFamily="#font/telly_humble"
android:textSize="35dp"
android:text="jay" />

Android Textview Scrolling Issue

Firstly, I am new to android so if I have missed something basic I do apologise.
I have created a GridView to store some information. The GridView consists of a 3x6 grid. In each cell, there is an image and text directly under the image. As the GridView is so large I have implemented a scrollbar.
This is how the page should look normally and is when first loaded/selected :
Everything looks wonderful, however, when I scroll down to the bottom and then back up, the text seems to wrap up and then push the image out of place. I am not sure why this is?
This is how the page looks after I have scrolled down and they scroll back up :
For the GridView, I have an XML file with the GridView itself along with a TextView at the very top called content_rewards.xml. I have also create an XML file for each picture/text in the grid itself called relics_gridlayout.xml. I believe I am probably missing a property of the TextViews in either one of these files, however, I am not sure which one or which property. I don't think it has anything to do with the grid or adapter itself hence I will not include that code.
content_rewards.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fitsSystemWindows="true"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="25dp">
<GridView
android:id="#+id/customgrid"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#+id/os_texts"
android:columnWidth="100dp"
android:numColumns="auto_fit"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="35dp"
android:scrollbars="horizontal"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="116dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="B = 0 S = 0 G = 0"
android:textSize="24sp"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toTopOf="#+id/customgrid"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="8dp"
app:layout_constraintLeft_toLeftOf="parent"/>
</android.support.constraint.ConstraintLayout>
relics_gridlayout.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:padding="3dp">
<ImageView
android:id="#+id/os_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_below="#+id/os_images"
android:id="#+id/os_texts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is Just Dummy Text"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold"/>
</RelativeLayout>
Any help would be great. Thanks.
<?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="#ECEFF1"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/app_bar_main">
<GridView
android:id="#+id/grd1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:horizontalSpacing="6dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="6dp">
</GridView>
</RelativeLayout>
This should solve your problem.
The scrolling view behavior will handle the scrolling irrespective of the size
Now add the Text view out of the Relative layout to view it always.
Or have a parent as Nested scrolling View and allow the nested scrolling enabled as false
setNestedScrollingEnabled(false)
A sample from my code that I already have used successfully to resolve such issue
Use your Grid view instead of Recycler View.
If you want the Item Text View to be always of 2 lines then set munLines="2" in the item Layout
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_container_reports"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/tab_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="#string/user_reports"
android:textAllCaps="true"
android:textColor="#color/colorPrimaryDark"
android:textSize="#dimen/tab_label"
app:textAllCaps="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/reports_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:nestedScrollingEnabled="false"
android:padding="4dp" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
This is a problem that i faced as well , the only solution that i could come up with was hardcoding the height of the grid item.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="3dp">
A better option would be to use recycler view with a grid layout manager.
you can use LinearLayout and assign weights so that every item in your grid view occupy same space
Update the relics_gridlayout.xml with below code ( you may need to adjust gravity and layout weights)Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearLayout_root_single_home_option"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/os_images"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:layout_weight="9" />
<TextView
android:id="#+id/os_texts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Just Dummy Text"
android:textSize="18dp"
android:textStyle="bold"
android:layout_weight="1" />
</LinearLayout>

Categories

Resources