padding issue in NetworkImageView on navigation header - android

I have implemented code for navigation header where I am using one NetworkImageView and image is shown with padding 10dp on left side my issue is I used android:layout_centerVertical="true" but it's not working on lollipop, marshmallow version. I run my app on kitkat version then the image has left padding with center vertical. Please tell me where I am wrong?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingBottom="20dp"
android:background="#e6e3e3"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:layout_width="50dp"
android:layout_height="80dp"
android:scaleType="fitXY"
android:id="#+id/imageView1"/>
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:singleLine="true"
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/imageView1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:id="#+id/tv_email"
android:textStyle="bold"
android:singleLine="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/imageView1"
android:layout_below="#+id/tv_name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reg Date : "
android:textSize="10dp"
android:textStyle="bold"
android:id="#+id/reg_date"
android:singleLine="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/imageView1"
android:layout_below="#+id/tv_email"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:id="#+id/tv_reg_date"
android:singleLine="true"
android:layout_marginLeft="1dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/reg_date"
android:layout_below="#+id/tv_email"/>
<TextView
android:id="#+id/lastlogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/reg_date"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/imageView1"
android:singleLine="true"
android:text="Last Login : "
android:textSize="10dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:id="#+id/last_login"
android:singleLine="true"
android:layout_marginLeft="1dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/lastlogin"
android:layout_below="#+id/tv_reg_date"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Membership : "
android:textStyle="bold"
android:textSize="10dp"
android:id="#+id/membershipStatus"
android:singleLine="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/imageView1"
android:layout_below="#+id/lastlogin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:id="#+id/tv_status"
android:singleLine="true"
android:layout_marginLeft="1dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/membershipStatus"
android:layout_below="#+id/last_login"/>
</RelativeLayout>

Please check your layout file. Its not version issue.

Related

Android Relative Layout Bottom to Bottom Side By Side Problem

I have to show two text views in a side by side layout. In addition I have to do this in 3 columns but I have to put them side by side. I did it one under the other but I couldn't side by side them all together unfortunately. What I want to do is: I want to bring these together, but it must be in a layout. I would really appreciate it if you show me how I can do this in the relative layout.
Screenshot
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:layout_marginTop="5dp">
<TextView
android:id="#+id/calismalartext"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="#font/roboto"
android:gravity="center"
android:lines="1"
android:padding="2dp"
android:text="Çalışmalar"
android:textColor="#color/colorBlack"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="#+id/prof_Works"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:layout_below="#+id/calismalartext"
android:gravity="center"
android:lines="1"
android:padding="1dp"
android:text=""
android:background="#drawable/rounded_rectangle_orange"
android:textColor="#color/colorBlack"
android:textSize="13sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginTop="5dp">
<TextView
android:id="#+id/takiptext"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="#font/roboto"
android:gravity="center"
android:lines="1"
android:padding="2dp"
android:text="Takip"
android:textColor="#color/colorBlack"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="#+id/prof_Follows"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_rectangle_orange"
android:ellipsize="end"
android:gravity="center"
android:layout_below="#+id/takiptext"
android:lines="1"
android:padding="1dp"
android:text=""
android:textColor="#color/colorBlack"
android:textSize="13sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_marginTop="5dp">
<TextView
android:id="#+id/takipcitext"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto"
android:gravity="center"
android:lines="1"
android:padding="2dp"
android:text="Takipçi"
android:textColor="#color/colorBlack"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="#+id/prof_Followers"
android:layout_width="100dp"
android:background="#drawable/rounded_rectangle_orange"
android:layout_height="wrap_content"
android:gravity="center"
android:lines="1"
android:layout_below="#+id/takipcitext"
android:padding="1dp"
android:text=""
android:textColor="#color/colorBlack"
android:textSize="13sp" />
</RelativeLayout>

Making Android Layout Scrollable

I am developing an Android App inside Visual Studio and I cant figure out how to make it scroll.
I am posting my AXML pastebin link!
AXML file
Thank you
Put your xml stuff inside a ScrollView. You should also change the android:layout_height of your root LinearLayout to wrap_content.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0ffa0"
android:scrollIndicators="right"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="65.3dp"
android:background="#aecc0a"
android:orientation="horizontal">
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="48.3dp"
android:layout_height="41.0dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:adjustViewBounds="true"
android:background="#aecc0a"
android:clickable="true"
android:hapticFeedbackEnabled="true"
android:scaleType="fitStart"
android:src="#drawable/backbutton"/>
<TextView
android:id="#+id/loginLabel1"
android:layout_width="62.0dp"
android:layout_height="24.0dp"
android:layout_marginLeft="98dp"
android:layout_marginTop="25dp"
android:text="LOGIN"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="20dp"
android:textStyle="bold"/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="54.7dp"
android:layout_height="42.7dp"
android:layout_marginLeft="80dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:src="#drawable/loginicon2"/>
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="3.0dp"
android:layout_marginBottom="0dp"
android:background="#414347"
android:clickable="false"
android:text="Button"/>
<TextView
android:id="#+id/loginlabel3"
android:layout_width="258.3dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginTop="20dp"
android:text="ENTER YOUR DETAILS"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="25dp"
android:textStyle="bold"/>
<Button
android:id="#+id/button1"
android:layout_width="310dp"
android:layout_height="3.0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:background="#414347"
android:clickable="false"
android:text="Button"/>
<TextView
android:id="#+id/loginLabel1"
android:layout_width="148.3dp"
android:layout_height="wrap_content"
android:layout_marginLeft="120dp"
android:layout_marginTop="50dp"
android:text="CUSTOMER ID"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="20dp"
android:textStyle="bold"
android:typeface="serif"/>
<EditText
android:id="#+id/loginCustID"
android:layout_width="144.0dp"
android:layout_height="37.0dp"
android:layout_marginLeft="120dp"
android:layout_marginTop="5dp"
android:background="#ffffff"
android:editable="true"
android:hint="*Required"
android:inputType="numberSigned"
android:maxLength="8"
android:text="1234565432456"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="30dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/loginLabel4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="30dp"
android:text="PASSWORD"
android:textAlignment="center"
android:textAllCaps="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textIsSelectable="false"
android:textSize="20dp"
android:textStyle="bold"/>
<EditText
android:id="#+id/loginPassword"
android:layout_width="200.0dp"
android:layout_height="37.0dp"
android:layout_marginLeft="95dp"
android:layout_marginTop="7dp"
android:background="#ffffff"
android:inputType="text"
android:password="true"
android:text="1234567890"
android:textColor="#000000"
android:textIsSelectable="false"
android:textSize="30dp"
android:textStyle="bold"/>
<Button
android:id="#+id/loginSubmit"
android:layout_width="140.5dp"
android:layout_height="66.0dp"
android:layout_marginLeft="120dp"
android:layout_marginTop="60dp"
android:background="#5dea4b"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:text="LOGIN"
android:textAlignment="center"
android:textSize="25dp"
android:textStyle="bold"/>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="3.0dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="50dp"
android:background="#414347"
android:clickable="false"
android:text="Button"/>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="260.0dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="230.3dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:scrollbarStyle="insideOverlay"
android:text="* Customer ID is 8 digits long"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="italic"/>
<TextView
android:id="#+id/textView2"
android:layout_width="235.0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="* Password is 8-10 digits long"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="italic"/>
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="2.7dp"
android:layout_height="92.7dp"
android:background="#414347"
android:clickable="false"/>
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="89.0dp"
android:layout_height="78.0dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:background="#f0ffa0"
android:scaleType="fitCenter"
android:src="#drawable/easeofaccess"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

Alignment of Image in Listview items android

If anyone could guide me what I am doing wrong in this ? I can't get my items aligned properly.
My list item
And My screen image
Here is my XML of child row. I am binding it with relative layout , then setting fixed length of image and other details are mentioned below. Please have a look. The image isn't appearing in the center as it is supposed to be.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:padding="5dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_alignBottom="#+id/Description_txt"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:padding="2dp"
android:src="#drawable/gallery" />
<TextView
android:id="#+id/Name_txt"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/arabella"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="#color/colorPrimaryDark"/>
<TextView
android:id="#+id/Brandname_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Name_txt"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/arabella"
android:textSize="11sp"
android:textColor="#color/black_overlay"
android:layout_alignRight="#+id/Description_txt"
android:layout_alignEnd="#+id/Description_txt" />
<TextView
android:id="#+id/Description_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Brandname_txt"
android:layout_marginLeft="5dp"
android:textSize="11sp"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/arabella"
android:textColor="#color/black_overlay" />
<TextView
android:id="#+id/Phone_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/Description_txt"
android:layout_alignBottom="#+id/Description_txt"
android:layout_toEndOf="#+id/Name_txt"
android:layout_toRightOf="#+id/Name_txt"
android:text="#string/arabella"
android:textSize="11sp"
android:textColor="#color/black_overlay" />
<Button
android:id="#+id/View_btn"
android:layout_width="60dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="5dp"
android:background="#drawable/btn_view"
android:paddingLeft="5dp"
android:textColor="#android:color/white"
android:textSize="7sp" />
<TextView
android:id="#+id/Viewed_txt"
android:visibility="gone"
android:textSize="11sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/View_btn"
android:layout_alignBottom="#+id/View_btn"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:layout_toLeftOf="#+id/View_btn"
android:layout_toStartOf="#+id/View_btn"
android:text="#string/viewed"
android:textStyle="bold"
android:textColor="#color/colorPrimaryDark" />
<ImageView android:id="#+id/imgView"
android:visibility="gone"
android:src="#drawable/ic_small_view"
android:layout_width="30dp"
android:layout_height="20dp"
android:layout_toLeftOf="#+id/Viewed_txt"
android:layout_toStartOf="#+id/Viewed_txt"
android:layout_alignBottom="#+id/Name_txt" />
</RelativeLayout>
you can just change the
1 change the height of your list item layout to
android:layout_height="wrap_content"
2 change the gravity of imageView to center
Depending on what layout your using. Use either:
layout_centerVertical="true"
or
gravity="center_vertical"
Also, make the imageView smaller
Use Below XML :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:src="#drawable/saffron_flag" />
<Button
android:id="#+id/View_btn"
android:layout_width="60dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="#drawable/saffron_flag"
android:paddingLeft="5dp"
android:textColor="#android:color/white"
android:textSize="7sp" />
<TextView
android:id="#+id/Name_txt"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="#+id/View_btn"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/arabella"
android:textColor="#color/colorPrimaryDark"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/Brandname_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Name_txt"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="#+id/View_btn"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/arabella"
android:textColor="#color/black_overlay"
android:textSize="11sp" />
<TextView
android:id="#+id/Description_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Brandname_txt"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="#+id/View_btn"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/arabella"
android:textColor="#color/black_overlay"
android:textSize="11sp" />
<TextView
android:id="#+id/Phone_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp"
android:layout_below="#+id/Description_txt"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/arabella"
android:textColor="#color/black_overlay"
android:textSize="11sp" />
<TextView
android:id="#+id/Viewed_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/View_btn"
android:layout_alignBottom="#+id/View_btn"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:layout_toLeftOf="#+id/View_btn"
android:layout_toStartOf="#+id/View_btn"
android:text="#string/viewed"
android:textColor="#color/colorPrimaryDark"
android:textSize="11sp"
android:textStyle="bold"
android:visibility="gone" />
<ImageView
android:id="#+id/imgView"
android:layout_width="30dp"
android:layout_height="20dp"
android:layout_alignBottom="#+id/Name_txt"
android:layout_toLeftOf="#+id/Viewed_txt"
android:layout_toStartOf="#+id/Viewed_txt"
android:src="#drawable/ic_small_view"
android:visibility="gone" />
</RelativeLayout>

Centering text within editText Android

I have a linearlayout with a textview, and edittext. How do I center the text within edittext. It appears to be drawn to the bottom as shown below.I want it to be consistent with the baseline similar to that of the textview to its left.
The layout code is as below:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="75dp"
android:layout_height="30dp"
android:ems="10"
android:textAlignment="center"
android:text="NAME"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:singleLine="true"
android:id="#+id/tv_name"
android:background="#drawable/orange_left_rounded_corner"
/>
<EditText
android:layout_width="125dp"
android:layout_height="30dp"
android:ems="10"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:text=""
android:layout_gravity="right"
android:gravity="center_horizontal"
android:textColor="#000000"
android:textSize="16sp"
android:singleLine="true"
android:id="#+id/et_name"
android:background="#drawable/orange_right_rounded_corner"
/>
</LinearLayout>
Use android:gravity="center" to have the input be centered
Just do that
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="75dp"
android:layout_height="30dp"
android:ems="10"
android:textAlignment="center"
android:text="NAME"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:singleLine="true"
android:id="#+id/tv_name"
android:background="#drawable/orange_left_rounded_corner"
android:gravity="center_vertical"
/>
<EditText
android:layout_width="125dp"
android:layout_height="30dp"
android:ems="10"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:text=""
android:layout_gravity="right"
android:gravity="center_horizontal"
android:textColor="#000000"
android:textSize="16sp"
android:singleLine="true"
android:id="#+id/et_name"
android:background="#drawable/orange_right_rounded_corner"
/>
Try with this code
<?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"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_name"
android:layout_width="75dp"
android:layout_height="30dp"
android:background="#drawable/orange_left_rounded_corner"
android:ems="10"
android:gravity="center_vertical"
android:singleLine="true"
android:text="NAME"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="16sp" />
<EditText
android:id="#+id/et_name"
android:layout_width="125dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:background="#drawable/orange_right_rounded_corner"
android:ems="10"
android:gravity="center_horizontal"
android:singleLine="true"
android:text=""
android:textAlignment="center"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>

How to prevent truncation in RelativeLayout

I am making an application to display movies sorted by Popularity and date.
When I click on a movie, it takes me to the description of the movie. I am using RelativeLayout for the description UI. But the movie name is truncated if its too large.
I have tried few solutions from stackoverflow for the textView like
android:scrollHorizontally="true"
android:ellipsize="end"
android:lines="1"
I know there's one solution of using LinearLayout. But I wanted to know if there's a solution using RelativeLayout only.
Please Find the screenshot by clicking on this link. The text gets truncated and its replaced by three dots
Here's the full code :
<ScrollView 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:fillViewport="true">
<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="?android:attr/listPreferredItemHeight"
android:paddingStart="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin_less"
android:paddingTop="#dimen/activity_vertical_margin_less"
android:paddingBottom="#dimen/activity_vertical_margin_less"
tools:context="com.example.puneet.movieout.MovieInfoDisplay"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Movie Title"
android:id="#+id/textView"
android:textStyle="bold"
android:layout_below="#+id/imageView"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:textColor="#color/black"
android:textSize="20sp" />
<TextView
android:scrollHorizontally="true"
android:ellipsize="end"
android:lines="1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Movie name is Long. Movie name is Long"
android:layout_marginTop="20dp"
android:id="#+id/textView2"
android:layout_above="#+id/textView4"
android:layout_toRightOf="#id/textView"
android:layout_alignStart="#+id/textView6"
android:layout_below="#+id/imageView"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Rating"
android:id="#+id/textView3"
android:textStyle="bold"
android:layout_below="#+id/textView2"
android:layout_alignParentStart="true"
android:textColor="#color/black"
android:textSize="20sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Rating"
android:layout_toRightOf="#id/textView3"
android:id="#+id/textView4"
android:layout_below="#+id/textView"
android:layout_alignStart="#+id/textView6"
android:textSize="20sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Release Date"
android:id="#+id/textView5"
android:textStyle="bold"
android:layout_below="#+id/textView3"
android:layout_alignParentStart="true"
android:textColor="#color/black"
android:layout_marginRight="10dp"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView6"
android:layout_toRightOf="#id/textView5"
android:layout_below="#+id/textView4"
android:textSize="20sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Overview"
android:id="#+id/textView7"
android:textStyle="bold"
android:layout_below="#+id/textView5"
android:layout_alignParentStart="true"
android:textColor="#color/black"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView8"
android:layout_toRightOf="#id/textView7"
android:layout_below="#+id/textView6"
android:layout_alignStart="#+id/textView6"
android:textSize="20sp"/>
</RelativeLayout>
</ScrollView>
If you don't want to get the text truncated , you have to remove the ellipsize attribute and add your TextView inside HorizontalScrollView.
Your view should be like :
<HorizontalScrollView
android:id="#+id/txt_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_above="#+id/textView4"
android:layout_toRightOf="#id/textView"
android:layout_alignStart="#+id/textView6"
android:layout_below="#+id/imageView"
android:scrollbars="none"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Movie name is Long. Movie name is Long"
android:id="#+id/textView2"
android:textSize="20sp"/>
</HorizontalScrollView>
This way you can embed your text inside the scroll without the text being truncated.

Categories

Resources