Perfect GridLayout in android - android

I want to make a gridlayout like shown below:
and to make so I made my layout like this.
<GridLayout
android:id="#+id/glColumns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tvIntro"
android:layout_marginRight="43dp"
android:layout_marginTop="3dp"
android:columnCount="4"
android:rowCount="6"
android:layout_toRightOf="#+id/tvLink1"
>
<LinearLayout
android:id="#+id/rlColumn1"
android:layout_width="wrap_content"
android:layout_marginRight="3dp"
android:orientation="vertical"
android:background="#color/button_bg"
android:layout_row="0"
android:layout_column="0"
android:layout_rowSpan="3"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvPassengerInt"
style="#style/subInfoInt"
android:text="#string/passenger_int" />
<TextView
android:id="#+id/tvPassengerText"
style="#style/subInfo"
android:text="#string/passenger" />
</LinearLayout>
<LinearLayout
android:id="#+id/rlColumn2"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_rowSpan="3"
android:layout_marginRight="3dp"
android:background="#color/button_bg"
android:orientation="vertical" >
<TextView
android:id="#+id/tvPassengerInts"
style="#style/subInfoInt"
android:layout_width="match_parent"
android:text="#string/passenger_int" />
<TextView
android:id="#+id/tvPassengerTexts"
style="#style/subInfo"
android:layout_width="match_parent"
android:text="#string/passenger" />
</LinearLayout>
<LinearLayout
android:id="#+id/rlColumn3"
android:layout_width="wrap_content"
android:layout_marginRight="3dp"
android:orientation="vertical"
android:layout_rowSpan="2"
android:background="#color/button_bg"
android:layout_row="0"
android:layout_column="3"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvPassengerInt2s"
style="#style/subInfoInt"
android:text="71,000" />
<TextView
android:id="#+id/tvPassengerText2s"
style="#style/subInfo"
android:text="STRUCTURES" />
</LinearLayout>
<!-- ========================================================== -->
<LinearLayout
android:layout_marginTop="3dp"
android:id="#+id/rlColumn11"
android:layout_width="wrap_content"
android:layout_marginRight="3dp"
android:orientation="vertical"
android:background="#color/button_bg"
android:layout_row="3"
android:layout_column="0"
android:layout_rowSpan="3"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvPassengerInt11"
style="#style/subInfoInt"
android:text="#string/passenger_int" />
<TextView
android:id="#+id/tvPassengerText1"
style="#style/subInfo"
android:text="#string/passenger" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="3dp"
android:id="#+id/rlColumn21"
android:layout_width="wrap_content"
android:layout_marginRight="3dp"
android:orientation="vertical"
android:layout_row="3"
android:layout_column="1"
android:layout_rowSpan="3"
android:background="#color/button_bg"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvPassengerInts1"
style="#style/subInfoInt"
android:text="#string/passenger_int" />
<TextView
android:id="#+id/tvPassengerTexts1"
style="#style/subInfo"
android:text="#string/passenger" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="3dp"
android:id="#+id/rlColumn211"
android:layout_width="wrap_content"
android:layout_marginRight="3dp"
android:orientation="vertical"
android:layout_row="3"
android:layout_column="2"
android:layout_rowSpan="3"
android:background="#color/button_bg"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvPassengerIntss1"
style="#style/subInfoInt"
android:text="#string/passenger_int" />
<TextView
android:id="#+id/tvPassengerTextss1"
style="#style/subInfo"
android:text="#string/passenger" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="3dp"
android:id="#+id/rlColumn31"
android:layout_width="wrap_content"
android:layout_marginRight="3dp"
android:layout_row="2"
android:layout_column="3"
android:layout_rowSpan="2"
android:orientation="vertical"
android:background="#color/button_bg"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvPassengerInt2s1"
style="#style/subInfoInt"
android:text="170" />
<TextView
android:id="#+id/tvPassengerText2s1"
style="#style/subInfo"
android:text="CITIES" />
</LinearLayout>
<!-- ========================================================== -->
<LinearLayout
android:layout_marginTop="3dp"
android:id="#+id/rlColumn311"
android:layout_width="wrap_content"
android:layout_marginRight="3dp"
android:layout_row="4"
android:layout_column="3"
android:layout_rowSpan="2"
android:orientation="vertical"
android:background="#color/button_bg"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvPassengerInt2s1s"
style="#style/subInfoInt"
android:text="30" />
<TextView
android:id="#+id/tvPassengerText2s1s"
style="#style/subInfo"
android:text="YEARS EXPERIENCE" />
</LinearLayout>
</GridLayout>
I got the desired output but not perfectly. The errors are mentioned in the picture. The output is like this:
The space are not managed properly and also the row and column span are not proper
How I tried to do this::::

Please check the link.These are the external libraries for creating the custom gridview
https://github.com/maurycyw/StaggeredGridViewDemo
https://github.com/etsy/AndroidStaggeredGrid
https://github.com/jacobmoncur/QuiltViewLibrary

Related

Android layout not behaving as expected

I'm using Android Studio to try and design a view with a GridLayout at the, a GridView in the middle and a Button at the bottom.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<RadioGroup
android:id="#+id/deliveryType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/radWaitingOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/waiting" />
<RadioButton
android:id="#+id/radCollectionOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/collection" />
<RadioButton
android:id="#+id/radDeliveryOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delivery" />
</RadioGroup>
<GridLayout
android:id="#+id/customerDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin">
<TextView
style="#style/caption"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/name" />
<TextView
android:id="#+id/customerName"
style="#style/text"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/name" />
<TextView
style="#style/caption"
android:layout_row="1"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/address" />
<TextView
android:id="#+id/customerAddress"
style="#style/text"
android:layout_row="1"
android:layout_column="1"
android:layout_columnWeight=".5"
android:lines="4"
android:maxLines="4"
android:text="#string/address" />
<TextView
style="#style/caption"
android:layout_row="2"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/phone" />
<TextView
android:id="#+id/customerPhone"
style="#style/text"
android:layout_row="2"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/phone" />
</GridLayout>
<RadioGroup
android:id="#+id/deliveryCost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#id/customerDetails">
<RadioButton
android:id="#+id/radLocalOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_00" />
<RadioButton
android:id="#+id/radNearOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_50" />
<RadioButton
android:id="#+id/radFarOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_00" />
</RadioGroup>
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<GridLayout
android:id="#+id/filter"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_height="wrap_content">
<TextView
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="#dimen/margin"
android:text="#string/filter" />
<EditText
android:id="#+id/txtFilter"
style="#style/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="#dimen/margin"
android:hint="#string/filter_customers" />
</GridLayout>
<GridView
style="#style/margin"
android:id="#+id/customers"
app:layout_constraintTop_toBottomOf="#id/filter"
app:layout_constraintBottom_toTopOf="#+id/addButton"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="wrap_content"
android:layout_height="0dp">
</GridView>
<Button
style="#style/margin"
android:id="#+id/addButton"
android:layout_width="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content"
android:text="Add"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
In the Android Studio designer it appears as I would expect:
but when it shows in the Android emulator, the Gridview appears to be expanded over the bottom of the screen and the button is not showing.
Can any give me pointers to what I have done wrong. Bare in mind this is my first attempt and a Kotlin program, coming from a dotnet background. Layout is so much easier in XAML :)
If you want the LinearLayout, ConstraintLayout and the button to stack up on top of each other, this should do it. It may need a bit of change on your end.
Replace your XML code with this and check:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:baselineAligned="false">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<RadioGroup
android:id="#+id/deliveryType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/radWaitingOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/waiting" />
<RadioButton
android:id="#+id/radCollectionOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/collection" />
<RadioButton
android:id="#+id/radDeliveryOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delivery" />
</RadioGroup>
<GridLayout
android:id="#+id/customerDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin">
<TextView
style="#style/caption"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/name" />
<TextView
android:id="#+id/customerName"
style="#style/text"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/name" />
<TextView
style="#style/caption"
android:layout_row="1"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/address" />
<TextView
android:id="#+id/customerAddress"
style="#style/text"
android:layout_row="1"
android:layout_column="1"
android:layout_columnWeight=".5"
android:lines="4"
android:maxLines="4"
android:text="#string/address" />
<TextView
style="#style/caption"
android:layout_row="2"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/phone" />
<TextView
android:id="#+id/customerPhone"
style="#style/text"
android:layout_row="2"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/phone" />
</GridLayout>
<RadioGroup
android:id="#+id/deliveryCost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#id/customerDetails">
<RadioButton
android:id="#+id/radLocalOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_00" />
<RadioButton
android:id="#+id/radNearOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_50" />
<RadioButton
android:id="#+id/radFarOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_00" />
</RadioGroup>
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<GridLayout
android:id="#+id/filter"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_height="wrap_content">
<TextView
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="#dimen/margin"
android:text="#string/filter" />
<EditText
android:id="#+id/txtFilter"
style="#style/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="#dimen/margin"
android:hint="#string/filter_customers" />
</GridLayout>
<GridView
style="#style/margin"
android:id="#+id/customers"
app:layout_constraintTop_toBottomOf="#id/filter"
app:layout_constraintBottom_toTopOf="#+id/addButton"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="wrap_content"
android:layout_height="0dp">
</GridView>
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
style="#style/margin"
android:id="#+id/addButton"
android:layout_width="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content"
android:text="Add"/>
</LinearLayout>

onMeasure of custom expandable listview calling too many times

I have seen similar kind of questions in SO but it didn't solve my issue. So I'm posting it as a new question.
I have a custom expandable listview inside a scrollview and setting isExpanded true always. This expandable listview's(ExpandableHeightListView
in the below layout xml) adapter has a custom edittext, When I click on edittext it calls the onMeasure of Custom ExpandableListview infinitely. This is happening only in devices have Lollipop and above.
Can anybody point out me what I'm doing wrong. Yea I know its not a good approach to use listview inside a scrollview but its an old implementation which cannot be changed due to some functional requirements.
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/goods_receipt_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/abstract_blue_land">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="#dimen/page_padding">
<TextView
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#android:color/transparent" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cell_header_background"
android:padding="#dimen/cell_padding"
android:text="#string/purchase_order_details"
android:textAppearance="#style/section_header" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cell_content_background"
android:columnCount="2"
android:padding="#dimen/cell_padding"
android:rowCount="2"
android:stretchColumns="*">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/purchase_order" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=": " />
<TextView
android:id="#+id/pur_ord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="right"
android:layout_row="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/type" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=": " />
<TextView
android:id="#+id/doc_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="1"
android:orientation="horizontal"
android:paddingTop="3dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/created_on" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=": " />
<TextView
android:id="#+id/created_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="right"
android:layout_row="1"
android:orientation="horizontal"
android:paddingTop="3dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/created_by" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=": " />
<TextView
android:id="#+id/created_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold" />
</LinearLayout>
</GridLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="10dip"
android:background="#color/transparent_highlight"
android:orientation="horizontal"
android:padding="#dimen/input_section_padding">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/items"
android:textAppearance="#style/section_header" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
<TextView
android:id="#+id/items_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="#style/section_header" />
</LinearLayout>
<LinearLayout
android:id="#+id/list_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cell_header_background"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:gravity="center_vertical"
android:minEms="5"
android:padding="5dip"
android:text="#string/item"
android:textColor="#color/button_background_light"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="2"
android:gravity="center_vertical"
android:minEms="2"
android:padding="5dip"
android:text="#string/dflag"
android:textColor="#color/button_background_light"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_vertical"
android:padding="5dip"
android:text="#string/material"
android:textColor="#color/button_background_light"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center_vertical"
android:padding="5dip"
android:text="#string/plant"
android:textColor="#color/button_background_light"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_vertical"
android:padding="5dip"
android:text="#string/ordered_qty"
android:textColor="#color/button_background_light"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_vertical"
android:padding="5dip"
android:text="#string/posted_qty"
android:textColor="#color/button_background_light"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_vertical"
android:padding="5dip"
android:text="#string/posting_qty"
android:textColor="#color/button_background_light"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical"
android:padding="5dip"
android:text="#string/uom"
android:textColor="#color/button_background_light"
android:textStyle="bold" />
</LinearLayout>
<com.sample.template.utils.ExpandableHeightListView
android:id="#+id/list_goods_receipt_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<com.sample.template.utils.ExpandableHeightGridView
android:id="#+id/goods_receipt_po_items_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="10dip"
android:numColumns="2"
android:verticalSpacing="10dip" />
</LinearLayout>
</ScrollView>
If the question is too broad please let me know I'll update my question.
Regards

seekbar in gridLayout out of margin

I'm developing an android app in which I have a UI with some controls on a tts. I defined the layout in a xml file like this:
<GridLayout
android:id="#+id/vlmPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnPanel"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<TextView
android:id="#+id/volumeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="center_vertical"
android:layout_row="0"
android:text="Volume:" />
<SeekBar
android:id="#+id/volume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="center_vertical"
android:layout_row="0"/>
<TextView
android:id="#+id/pitchLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_column="0"
android:layout_gravity="center_vertical"
android:layout_row="2"
android:text="Pitch:" />
<SeekBar
android:id="#+id/pitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center_vertical"
android:layout_row="2" />
<TextView
android:id="#+id/rateLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_column="0"
android:layout_gravity="center_vertical"
android:layout_row="3"
android:text="Rate:" />
<SeekBar
android:id="#+id/rate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center_vertical"
android:layout_row="3" />
</GridLayout>
The problem is that the seekbar goes out of the margin and I'm not able to fix this problem.
Try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/volumeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:text="Volume:" />
<SeekBar
android:id="#+id/volume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="center_vertical"
android:layout_row="0"
android:layout_weight="1"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/pitchLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_column="0"
android:layout_gravity="center_vertical"
android:layout_row="2"
android:text="Pitch:" />
<SeekBar
android:id="#+id/pitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center_vertical"
android:layout_row="2"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/rateLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_column="0"
android:layout_gravity="center_vertical"
android:layout_row="3"
android:text="Rate:" />
<SeekBar
android:id="#+id/rate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center_vertical"
android:layout_row="3"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
</LinearLayout>
I have changed your layout into my way try to use this its solve your problem.
Thank you

How to wrap text in a TexView?

Here is my layout:
<GridLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnCount="2"
android:orientation="horizontal"
android:rowCount="2" >
<ImageView
android:id="#+id/img"
android:layout_width="150dp"
android:layout_height="225dp"
android:layout_gravity="left|top"
android:layout_column="0"
android:layout_rowSpan="2"
android:contentDescription="#string/imgdesc" />
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_column="1"
android:layout_marginLeft="20dp"
android:layout_row="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="fill_horizontal"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_row="1"/>
</GridLayout>
And here is the result:
As you can see, a part of the text is out the screen and I don't really know how to fix it.
Try to use LinearLayout for your design instead of GridLayout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/img"
android:layout_width="150dp"
android:layout_height="225dp"
android:contentDescription="#string/imgdesc"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/tvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"/>
</LinearLayout>
</LinearLayout>
just replace below code with your current code, hope this work for you.
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnCount="2"
android:orientation="horizontal"
android:rowCount="2" >
<ImageView
android:id="#+id/img"
android:layout_width="100dp"
android:layout_height="225dp"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_rowSpan="2"
android:contentDescription="#string/app_name"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content" // this line change
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
android:layout_row="0"
android:ems="5" //this line added
android:layout_marginRight="10dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:ems="5"
android:layout_gravity="fill_horizontal"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_row="1" />
</GridLayout>
Note: there can be a many ways to do the same.
try below code, it will work
<?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="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/img"
android:layout_width="150dp"
android:layout_height="225dp"
android:layout_gravity="left|top"
android:layout_column="0"
android:layout_rowSpan="2"
android:scaleType="fitXY"
android:contentDescription="test" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_column="1"
android:layout_marginLeft="20dp"
android:layout_row="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="fill_horizontal"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_row="1"/>
</LinearLayout>
</LinearLayout>

How can use Scrollbar in android in this case?

in an XML file, I have 4 tablelayouts in which the rows are being created dynamically when the user inputs an item. however i want to give each table a specific space of the UI and then just have a scrollbar in each table in case there are too many items in each table.
How can i do that please?
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/AbsoluteLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/loggedas" />
<Space
android:layout_width="58dp"
android:layout_height="1dp" />
<Space
android:layout_width="46dp"
android:layout_height="1dp" />
<Space
android:layout_width="346dp"
android:layout_height="1dp" />
<Space
android:layout_width="1dp"
android:layout_height="51dp" />
<Space
android:layout_width="1dp"
android:layout_height="23dp" />
<Space
android:layout_width="1dp"
android:layout_height="50dp" />
<Space
android:layout_width="1dp"
android:layout_height="10dp" />
<Space
android:layout_width="1dp"
android:layout_height="82dp" />
<Space
android:layout_width="1dp"
android:layout_height="69dp" />
<Space
android:layout_width="1dp"
android:layout_height="66dp" />
<Space
android:layout_width="1dp"
android:layout_height="21dp" />
<Space
android:layout_width="60dp"
android:layout_height="1dp" />
<Space
android:layout_width="30dp"
android:layout_height="1dp" />
<Space
android:layout_width="10dp"
android:layout_height="1dp" />
<TextView
android:id="#+id/loggedastoedit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="138dp"
android:layout_y="0dp"
android:text="#string/loggedas"
android:textColor="#color/Black" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="1dp"
android:layout_y="15dp"
android:text="#string/youneed" />
<TextView
android:id="#+id/caloriesneeded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="66dp"
android:layout_y="16dp"
android:text="TextView"
android:textColor="#color/Red" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="146dp"
android:layout_y="17dp"
android:text="#string/caloriestextfield" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="191dp"
android:layout_y="17dp"
android:text="#string/today" />
<TableLayout
android:id="#+id/breakfasttableviewing"
android:layout_width="344dp"
android:layout_height="wrap_content"
android:layout_x="1dp"
android:layout_y="62dp" >
</TableLayout>
<TableLayout
android:id="#+id/lunchtableviewing"
android:layout_width="335dp"
android:layout_height="wrap_content"
android:layout_x="2dp"
android:layout_y="135dp" >
</TableLayout>
<TableLayout
android:id="#+id/dinnertableviewing"
android:layout_width="346dp"
android:layout_height="wrap_content"
android:layout_x="2dp"
android:layout_y="210dp" >
</TableLayout>
<Button
android:id="#+id/addexercisebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="373dp"
android:text="#string/addexercise" />
<Button
android:id="#+id/addmealbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="121dp"
android:layout_y="373dp"
android:text="#string/addfood" />
<Button
android:id="#+id/newday"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="209dp"
android:layout_y="373dp"
android:text="#string/newday" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="111dp"
android:layout_y="43dp"
android:text="#string/breakfast"
android:textStyle="bold" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_x="120dp"
android:layout_y="107dp"
android:text="#string/lunch"
android:textStyle="bold" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="121dp"
android:layout_y="184dp"
android:text="#string/dinner"
android:textStyle="bold" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="116dp"
android:layout_y="265dp"
android:text="#string/exercise"
android:textStyle="bold" />
<TableLayout
android:id="#+id/exercisetableviewing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="5dp"
android:layout_y="289dp" >
</TableLayout>
Wrap each tableView with ScrollView, and set on each ScrollView android:layout_weight property to divide the screen among them with proportions you desire;

Categories

Resources