Table weight ignored when text length is long? - android-linearlayout

I have the following xml layout - if editText_model text is fairly short then the table is split 50/50 by the weight value.
However the longer the text gets the more it squashes up the word Description. Why is it ignoring the 50/50 split?
<?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:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50"
android:paddingLeft="5dp"
android:text="Select"
android:textSize="15sp"/>
<RadioGroup
android:id="#+id/radioGroupAdd"
android:layout_weight="50"
android:orientation="horizontal">
<RadioButton
android:id="#+id/RadioModel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test1"/>
<RadioButton
android:id="#+id/RadioPaint"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Test2"/>
</RadioGroup>
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<TableRow>
<TextView
android:id="#+id/tV_model"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50"
android:gravity="center|left"
android:paddingLeft="5dp"
android:text="Description"
android:textSize="15sp"/>
<EditText
android:id="#+id/editText_model"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50"
android:hint="Enter Description"
android:inputType="text|textMultiLine|textNoSuggestions"
android:minLines="3"
android:text="testing long line of text 1234567890 123 456 77878 89 9 9d"
android:textSize="15sp"/>
</TableRow>
</TableLayout>
</LinearLayout>

For the layout_width, try putting 0dp.

Related

Combining two text views in single line

I want to align text view as mentioned below in my android application
totally two lines
in first line one text view layout weight 2
in second line one text view layout weight 2
the third text view combining both lines and the layout weight 1 and text alignment center
anyone please help me to get fixed this in my android application
the xml layout
<LinearLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/itemName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:importantForAutofill="no"
android:padding="15dp"
android:fontFamily="#font/bold"
android:textSize="20sp"
android:textColor="#color/black"
android:textAlignment="center"
tools:ignore="Deprecated,TouchTargetSizeCheck,DuplicateSpeakableTextCheck"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/eancode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:textAlignment="center"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/rate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:importantForAutofill="no"
android:selectAllOnFocus="true"
android:padding="25dp"
android:fontFamily="#font/bold"
android:textSize="40sp"
android:textAlignment="center"
android:textColor="#color/black"
tools:ignore="Deprecated,TouchTargetSizeCheck,SpeakableTextPresentCheck" />
</LinearLayout>
</LinearLayout>
thank you

How to constrain a ScrollView with dynamic contents?

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="25dp">
<TableLayout
android:id="#+id/tableLayoutHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewDeviceName">
</TableLayout>
<ScrollView
android:id="#+id/scrollViewLayoutFoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:minWidth="150dp"
android:minHeight="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableLayoutHeader">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/red"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayoutFragments1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" />
<LinearLayout
android:id="#+id/linearLayoutFragments2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
linearLayoutFragments1 and linearLayoutFragments2 have many fragments added at runtime. Unfortunately, scrollViewLayoutFoo is not constrained below tableLayoutHeader, but overflows into tableLayoutHeader.
Could anyone offer a tip on how to fix this?
You were missing some constraints.
You need to constraint the TabLayout to the parent from start/top/end and scroll view constraint to the bottom of it.
There are also referenced some views that are not in the example so you might have to update them accordingly.
<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:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:id="#+id/tableLayoutHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_height="48dp" />
<ScrollView
android:id="#+id/scrollViewLayoutFoo"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:minHeight="60dp"
android:minWidth="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableLayoutHeader">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayoutFragments1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<LinearLayout
android:id="#+id/linearLayoutFragments2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>

Line up text under each other in Layout

I have created a payment info screen but would like to adjust it to make it look more like the image below. I have added below my attempted code. How do I go about doing this? Any help would be greatly appreciated. I would like to know how to split the layout into 3 sections and have buttons like the image. Also how would I align my text to be under each other?
Image of what I would like to achieve
Code Below
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:orientation="vertical"
android:background="#color/colorPrimary"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/solver"/>
<View
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record phone calls"
android:textColor="#color/colorWhite"
android:layout_gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Know who viewed your profile"
android:textColor="#color/colorWhite"
android:layout_gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option to view profiles privately"
android:textColor="#color/colorWhite"
android:layout_gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get the Premium badge on your profile"
android:textColor="#color/colorWhite"
android:layout_gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30 contact requests a month"
android:layout_gravity="center"
android:textColor="#color/colorWhite"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No ads"
android:layout_gravity="center"
android:textColor="#color/colorWhite"
android:textSize="18sp"/>
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monthly Premium R19,19"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yearly Premium R179,99"/>
</LinearLayout>
</ScrollView>
Don't use scrollView. Use a vertical LinearLayout and give it's children suitable weights
Something Like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:weight="1.25">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:weight="1"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
And for transparensy use this style for your activity in manifest
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#66000000</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowFullscreen">true</item>
</style>

How to put fragment on top of soft kevboard?

I have an Android fragment with a EditText. Since I would like to enter there something, I managed to display the keyboard as well, when opening this fragment.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/viewgroup_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/viewgroup_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/view_placeholder"
android:layout_width="match_parent"
android:layout_height="336dp"
android:clickable="false"
android:src="#drawable/img_placeholder_400"
android:layout_weight="0.64" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/margin_bot"
android:paddingLeft="#dimen/margin_left"
android:paddingRight="#dimen/margin_right"
android:paddingTop="20dp"
android:background="#color/dark"
android:focusableInTouchMode="true"
android:weightSum="1">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter name"
android:id="#+id/textView_fragment_title"
android:textColor="#color/white"
android:clickable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You can enter your name here.. "
android:id="#+id/textView_fragment_subtitle"
android:textColor="#color/blueTone" />
</LinearLayout>
<ImageButton
android:id="#+id/btn_close_fragment_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="#drawable/ic_darkblue_20"
android:layout_gravity="right"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/editText_fragment_content"
android:background="#color/white"
android:inputType="text"
android:imeOptions="actionDone"
android:hint="Enter name here ..."
android:layout_marginTop="10dp">
<requestFocus/>
</EditText>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
But my keyboard is in front of my fragment, and thus my fragment is not visible anymore.
I would like to have my keyboard on the bottom, and on top of my soft keybaord my fragment as in this example screenshot
How can I put my fragment on top of the Android soft keyboard?
Following solved my issue:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/viewgroup_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
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:focusableInTouchMode="true"
android:layout_alignParentBottom="true"
android:weightSum="1">
<MY_STUFF>
</LinearLayout>
</RelativeLayout>

adview not showing with bottom on linearlayout

I want to add applications to the ad. But I fail I want to add about the position advertised. Codes are as follows:
<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"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">
<TextView
android:id="#+id/tarih"
android:textColor="#04B038"
android:textSize="15dp"
android:textStyle="bold"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/olaylar_liste"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
<ProgressBar
android:layout_gravity="center_vertical|center_horizontal"
android:id="#+id/progress_olaylar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
<LinearLayout
android:layout_gravity="bottom"
android:orientation="horizontal"
android:id="#+id/adLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"></LinearLayout>
</LinearLayout>
I want adview showing bottom on linearlayout. Adview # + id /adLayout will be displayed on the Layout
Please help me.
try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">
<TextView
android:id="#+id/tarih"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:text="Header"
android:textColor="#04B038"
android:textSize="15dp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/adLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="#ff0000"
android:orientation="horizontal"></LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/adLayout"
android:layout_below="#+id/tarih">
<ListView
android:id="#+id/olaylar_liste"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
<ProgressBar
android:id="#+id/progress_olaylar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" />
</FrameLayout>
</RelativeLayout>

Resources