Android Relative Layout Bottom to Bottom Side By Side Problem - android

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>

Related

col and row spans in android table layout android

I want to make following layout in android but unable to make because i new to table layout and tried a lot to fix column spans and row spans.
This is what i had tried last, but the problem is the heading in first column, i want a row span of 2 but unable to do that so i put another blank row there.
<LinearLayout
android:id="#+id/fillable_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TableLayout
android:id="#+id/fixed_column_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_gravity="center_horizontal"
android:padding="2dp"
android:text="Account"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_gravity="center_horizontal"
android:padding="2dp"
android:text=""
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp">
<TableLayout
android:id="#+id/scrollable_table"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_gravity="center_horizontal"
android:layout_span="2"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Opening Balance"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:layout_gravity="center_horizontal"
android:layout_span="2"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Transaction During Period"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:layout_gravity="center_horizontal"
android:layout_span="2"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Closing Balance"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:background="#FFC7C7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Debit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FBFFC7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Credit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FFC7C7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Debit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FBFFC7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Credit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FFC7C7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Debit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FBFFC7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Credit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</HorizontalScrollView>
</LinearLayout>
Data in all rows are dynamic except headings.
Please help me.
Thanks

Responsive Table layout for different size screen android

When I am try to develop a simple table layout it's occur a problem. The layout is works fine for big screen. But when I'm use that in small phone then the problem create. The full rows aren't visible.
Can anyone help me out? I just want to make a simple table layout like that:
here what I made xml layout
<TableLayout
android:layout_below="#+id/jonosonkha"
android:layout_width="match_parent"
android:layout_height="250dp"
android:stretchColumns="5">
<TableRow>
<TextView
android:textColor="#000"
android:background="#ffea00"
android:textSize="20sp"
android:text="পরিবার"
android:paddingLeft="5dp" />
<TextView
android:background="#000"
android:textColor="#fff"
android:textSize="20sp"
android:text="পুরুষ"
android:gravity="left"
android:paddingLeft="5dp"/>
<TextView
android:background="#ffea00"
android:textSize="20sp"
android:text="মহিলা"
android:textColor="#000"
android:gravity="center"
android:paddingLeft="5dp" />
<TextView
android:background="#000"
android:textSize="20sp"
android:text="গড় সদস্য"
android:gravity="left"
android:textColor="#fff"
android:paddingLeft="5dp" />
<TextView
android:background="#ffea00"
android:textColor="#000"
android:textSize="20sp"
android:text="ঘনত্ব/কি.মি"
android:gravity="left"
android:paddingLeft="5dp" />
</TableRow>
<TableRow
android:layout_marginTop="2dp"
>
<TextView
android:textColor="#000"
android:background="#ffea00"
android:textSize="16sp"
android:text="৮৯৮৬৩"
android:paddingLeft="5dp" />
<TextView
android:background="#000"
android:textColor="#fff"
android:textSize="16sp"
android:text="২০৫০৭৫"
android:gravity="center"
android:paddingLeft="5dp"/>
<TextView
android:background="#ffea00"
android:textSize="16sp"
android:text="২০৯১১৩"
android:textColor="#000"
android:gravity="center"
android:paddingLeft="5dp" />
<TextView
android:background="#000"
android:textSize="16sp"
android:text="৪.৫৪"
android:gravity="center"
android:textColor="#fff"
android:paddingLeft="5dp" />
<TextView
android:background="#ffea00"
android:textColor="#000"
android:textSize="16sp"
android:text="২১৩৮"
android:gravity="left"
android:paddingLeft="5dp" />
</TableRow>
</TableLayout>
It's works fine for big screen but the problem is some of rows are covered by the small screen. Any solution please.
You want to divide five TextView .
You can add android:layout_width="0dp" 、android:layout_height="match_parent" and android:layout_weight="1" in your TextView .
You can try this .
<TableLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="#+id/jonosonkha"
android:stretchColumns="5">
<TableRow>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:paddingLeft="5dp"
android:text="পরিবার"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000"
android:gravity="left"
android:paddingLeft="5dp"
android:text="পুরুষ"
android:textColor="#fff"
android:textSize="20sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:gravity="center"
android:paddingLeft="5dp"
android:text="মহিলা"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000"
android:gravity="left"
android:paddingLeft="5dp"
android:text="গড় সদস্য"
android:textColor="#fff"
android:textSize="20sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:gravity="left"
android:paddingLeft="5dp"
android:text="ঘনত্ব/কি.মি"
android:textColor="#000"
android:textSize="20sp"/>
</TableRow>
<TableRow
android:layout_marginTop="2dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:paddingLeft="5dp"
android:text="৮৯৮৬৩"
android:textColor="#000"
android:textSize="16sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000"
android:gravity="center"
android:paddingLeft="5dp"
android:text="২০৫০৭৫"
android:textColor="#fff"
android:textSize="16sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:gravity="center"
android:paddingLeft="5dp"
android:text="২০৯১১৩"
android:textColor="#000"
android:textSize="16sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000"
android:gravity="center"
android:paddingLeft="5dp"
android:text="৪.৫৪"
android:textColor="#fff"
android:textSize="16sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:gravity="left"
android:paddingLeft="5dp"
android:text="২১৩৮"
android:textColor="#000"
android:textSize="16sp"/>
</TableRow>
</TableLayout>
Output
You should define the width attribute of the table rows, like:
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
and the weight attribute of all the Textviews:
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#000"
android:background="#ffea00"
android:textSize="20sp"
android:text="পরিবার"
android:paddingLeft="5dp" />

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>

Spaces are appearing on the right and left side of a Scroll View android?

I am developing an android application. On the preview the view is presanting the way I have set it but when I run it on a device I am seeing spaces on it right and left side.
Screen shots are attached for the better understanding of the problem.
Below is the code of my layout.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="------"
>
<!-- TODO: Update blank fragment layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrollView"
android:scrollbars="none"
android:layout_gravity="center">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/screen_background">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/telephone_number"
android:id="#+id/telephonNumberTextView"
android:phoneNumber="false"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/phoneNumberEditText"
android:layout_weight="1"
android:clickable="true"
android:singleLine="true"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:textAlignment="textStart" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/telephone_extension"
android:id="#+id/telephoneExtensionTextView"
android:layout_marginTop="10dp"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/telephoneExtensionEditText"
android:background="#drawable/edittext"
android:singleLine="true"
android:paddingLeft="4dp"
android:layout_weight="1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/email_id"
android:id="#+id/emailIdTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/emailIdEditText"
android:layout_gravity="center_vertical"
android:singleLine="true"
android:layout_weight="1"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_margin="5dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/problem_type"
android:id="#+id/problemTypeTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:text="#string/fetch_problem_types"
android:id="#+id/button"
android:background="#drawable/buttonback"
android:textColor="#android:color/white"
android:layout_gravity="center"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/location"
android:id="#+id/locationTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:ems="10"
android:id="#+id/locationEditText"
android:layout_gravity="bottom"
android:singleLine="true"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/brief_desc"
android:id="#+id/briefDescTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/briefDescEditText"
android:singleLine="true"
android:layout_gravity="bottom"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/doc_desc"
android:id="#+id/docDescTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/docDescEditText"
android:layout_gravity="bottom"
android:singleLine="true"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/approval_memo"
android:id="#+id/approvalMemoTextView"
android:layout_gravity="left|center_vertical"
android:layout_marginTop="10dp"
android:textColor="#android:color/white"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/approvalMemoEditText"
android:layout_gravity="bottom"
android:singleLine="true"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_weight="1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/requester_Name"
android:id="#+id/requesterNameTextView"
android:layout_gravity="left|center_vertical"
android:layout_marginTop="10dp"
android:textColor="#android:color/white"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/requesterNameEditText"
android:layout_gravity="bottom"
android:singleLine="true"
android:background="#drawable/edittext"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:paddingLeft="4dp"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:text="#string/submit_button_title"
android:id="#+id/submitButton"
android:layout_gravity="center_vertical"
android:background="#drawable/buttonback"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="5dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
The problem (most probably) lies in the top level XML. I assume you posted only the content.xml which is included my activity_main.xml, because I can't see the Floating Action Button.
I guess you used the build-in generator to create layouts for you and edited the content.xml one. The paddings are defined inside the activity_main.xml one. Delete them and you are good to go.
Remove layout android:layout_margin="5dp" in Email Id EditText
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/emailIdEditText"
android:layout_gravity="center_vertical"
android:singleLine="true"
android:layout_weight="1"
android:background="#drawable/edittext"
android:paddingLeft="4dp" />

Android - how to set margin relative to another control?

I'm really new to android and would appreciate any help from you.
I have a screen with different templates for two kind of products. Each template is a separate xml file where I place a bunch of controls. Every control has it's own exact place in the screen which I define with margins.
The problem is I don't know how long is going to be a text in the upper TextView. If there is a one line everything looks fine, but a few lines destroy it.
Is there any way to stretch upper textview and at the same time keep all the rest controls relative to this textview?
The code is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/regBackground"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/regBackground" >
<TextView
android:id="#+id/txtProductNameScreenD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="10dp"
android:layout_marginRight="18dp"
android:layout_marginTop="10dp"
android:text="#string/empty"
android:textColor="#color/_black"
android:textSize="16sp"
android:textStyle="bold"
android:lines="1"
android:ellipsize="end"
android:scrollHorizontally="true"
android:singleLine="true" >
</TextView>
<ImageView
android:id="#+id/imgProductBcgD"
android:layout_width="300dp"
android:layout_height="263dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:src="#drawable/frame_product_screen" >
</ImageView>
<ImageView
android:id="#+id/imgProductScreenD"
android:layout_width="250dp"
android:layout_height="260dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="42dp"
android:background="#color/_white" >
</ImageView>
<ImageView
android:id="#+id/imgProductScreendiscD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="205dp"
android:src="#drawable/discount_bkg_product_screen" >
</ImageView>
<TextView
android:id="#+id/txtProdScreenPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:layout_marginRight="45dp"
android:layout_marginTop="220dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="#string/empty"
android:textColor="#color/_black"
android:textSize="18sp" >
</TextView>
<TextView
android:id="#+id/txtPriceShekelD1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:layout_marginRight="80dp"
android:layout_marginTop="230dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="#string/shekel_symbol"
android:textColor="#color/_gray"
android:textSize="10sp" />
<TextView
android:id="#+id/txtBeforeDiscD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:layout_marginRight="25dp"
android:layout_marginTop="237dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="#string/before_discount"
android:textColor="#color/_gray"
android:textSize="10sp" />
<TextView
android:id="#+id/txtProdScreenDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:layout_marginRight="140dp"
android:layout_marginTop="220dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="#string/empty"
android:textColor="#color/_orange"
android:textSize="18sp" >
</TextView>
<TextView
android:id="#+id/txtDiscountD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:layout_marginRight="145dp"
android:layout_marginTop="237dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="#string/bonus"
android:textColor="#color/_gray"
android:textSize="10sp" />
<TextView
android:id="#+id/txtProdScreenDiscountPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|top"
android:layout_marginLeft="45dp"
android:layout_marginTop="220dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="#string/empty"
android:textColor="#color/_black"
android:textSize="18sp" >
</TextView>
<TextView
android:id="#+id/txtPriceShekelD2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|top"
android:layout_marginLeft="30dp"
android:layout_marginTop="230dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="#string/shekel_symbol"
android:textColor="#color/_gray"
android:textSize="10sp" />
<TextView
android:id="#+id/txtAfterDiscD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|top"
android:layout_marginLeft="30dp"
android:layout_marginTop="237dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="#string/after_discount"
android:textColor="#color/_gray"
android:textSize="10sp" />
<Button
android:id="#+id/btnShareFacebookD"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="255dp"
android:background="#drawable/facebook_button_product_screen" >
</Button>
<TextView
android:id="#+id/txtDatePSDiscD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_horizontal"
android:layout_marginRight="90dp"
android:layout_marginTop="315dp"
android:text="#string/exp_date"
android:textColor="#color/_gray"
android:textSize="14sp" >
</TextView>
<TextView
android:id="#+id/txtDateProductScreenD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_horizontal"
android:layout_marginLeft="90dp"
android:layout_marginTop="315dp"
android:text="#string/empty"
android:textColor="#color/_blue"
android:textSize="14sp" >
</TextView>
<ImageView
android:id="#+id/imgSeparatorProductScreenD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="345dp"
android:src="#drawable/separator_product_screen" >
</ImageView>
<TextView
android:id="#+id/txtDescriptionProductScreenD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="355dp"
android:inputType="textMultiLine"
android:text="#string/empty"
android:textColor="#color/_black"
android:textSize="12sp" >
</TextView>
</FrameLayout>
</LinearLayout>
I can constrain the text to be just single line with the following parameter
android:singleLine = "true"
Moreover, you can fade the edge of it, just to make it look better
android:fadeScrollbars = "true"
If you want the users to be able to read the whole text you can add a scrolling effect.
http://developer.android.com/reference/android/widget/TextView.html

Categories

Resources