I am considering about the white blank spacing.
I don't know the reason why white spacing exist in my gridview.
I attached '.xml' and the 'result screen shot. '
I am trying use the gravity things.. but It dosen't work.
Could anyone help me??
...I got stackoverflow error 'It looks like your position is mostly 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="match_parent"
android:background="#fff"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight="0.2">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#drawable/set_border"
android:gravity="center"
android:text="#string/msg_diary_plan"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.53"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/btn_backmonth"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:background="#android:color/transparent"
android:text="" />
<TextView
android:id="#+id/tv_date"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="0.8"
android:background="#android:color/transparent"
android:gravity="center"
android:paddingLeft="10dp"
android:textColor="#000"
android:textSize="20sp" />
<Button
android:id="#+id/btn_nextmonth"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:background="#android:color/transparent"
android:text="" />
</LinearLayout>
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.85"
android:listSelector="#ffff"
android:numColumns="7" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_alarm"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.17"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:orientation="vertical"
android:weightSum="1">
<Switch
android:id="#+id/sw_alarm"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Alarm" />
</LinearLayout>
<TimePicker
android:id="#+id/timePicker"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:timePickerMode="spinner" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1">
<Button
android:id="#+id/btn_alarm_submit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:text="SUBMIT"
android:textColor="#color/white" />
</LinearLayout>
</LinearLayout>
and the result is
and this is the gridview item layout. Thanks
<?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"
android:weightSum="1">
<TextView
android:id="#+id/tv_item_gridview"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.8"
android:textColor="#000" />
<TextView
android:id="#+id/isDone"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.2"
android:visibility="visible" />
It is because you have yout item layout set to match_parent but TextViews to wrap_content. So by default it stays at the start position.
To fix this set your TextViews width to match_parent and gravity to center android:gravity="center"
So your item layout will look as below:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="#+id/tv_item_gridview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:gravity="center"
tools:text="2"
android:textColor="#000" />
<TextView
android:id="#+id/isDone"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:gravity="center"
tools:text="13"
android:visibility="visible" />
</LinearLayout>
Related
I am seeing varying layout weights though i have specified a fixed layout weight.
From the below code you can see that statusLinearLayout is set with layout_weight to 0.2 and the remaining space by other layout.
I am using the below layout for a Recycler item.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:id="#+id/mainLinearLayout">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.2"
android:id="#+id/statusLinearLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="#+id/statusTextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.8">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/pNameTextView" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/hNameTextView" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:id="#+id/sTypeTextView" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:id="#+id/dateTextView" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorPrimary"
android:layout_below="#+id/mainLinearLayout"/>
</RelativeLayout>
Below is the UI what i am getting in emulator:
How to my statusLinearLayout to have a fixed length than variable lengths?
Try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLinearLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/statusLinearLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:orientation="vertical">
<TextView
android:id="#+id/statusTextView"
android:text="nilesh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:orientation="vertical">
<TextView
android:id="#+id/pNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="nilesh"
android:gravity="center" />
<TextView
android:id="#+id/hNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="nilesh"
android:gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/sTypeTextView"
android:layout_width="0dp"
android:text="nilesh"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" />
<TextView
android:id="#+id/dateTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="nilesh"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/mainLinearLayout"
android:background="#color/colorPrimary" />
</RelativeLayout>
RESULT
I have four textviews in my Linear Layout and they have equal
width as follows,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView86" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content" />
<TextView
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content" />
<TextView
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content" />
<TextView
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
My problem is, The textviews should be displayed with the same height.The content(text) for that textview will be set programmatically. I tried with Relative layout but the width of textview couldn't be same. I need both height and width should be same as tallest child.
Guide me please. Thanks!
Use below layout :
<LinearLayout
android:weightSum="1"
android:background="#color/colorPrimaryDark"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="#color/black_30"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="match_parent"
/>
<TextView
android:background="#color/com_facebook_blue"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="match_parent"
/>
<TextView
android:background="#color/tw__composer_red"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="match_parent"
/>
<TextView
android:background="#color/colorAccent"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="match_parent"
/>
</LinearLayout>
Checkout below xml Code , You set the child height to wrap_content that should be match_parent :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:background="#drawable/bluebackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView86" />
<LinearLayout
android:background="#color/colorPrimaryDark"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="#drawable/bluebackground"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
/>
<TextView
android:background="#drawable/bluebackground"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
/>
<TextView
android:background="#drawable/bluebackground"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
/>
<TextView
android:background="#drawable/bluebackground"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
I have a small question about linearlayouts.
Let's say i have, 1 horizontal linearlayout that contains 6 vertical linearlayouts.
I can make all linearslayouts the same width size if i use weightsum=12(of horizontal ll) and layout_weight=2(for vertical ll)
Result :
Now i want the "test1" layout to be 2 or 3 times smaller than the others.
I tried with weightsum=11, and layout_weigth=1(for the test1 layout) and layout_weight=2(for the others). I can't make it work, here is my code...
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="11">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:background="#drawable/border"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="2"
android:background="#drawable/border"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="2"
android:background="#drawable/border"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="2"
android:background="#drawable/border"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="2"
android:background="#drawable/border"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="2"
android:background="#drawable/border"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test"
/>
</LinearLayout>
</LinearLayout>
How can i do it?
Thank you.
You need to use : android:layout_width="0dp" for the Linearlayout with the android:layout_weight="1" set as 1.
Now i want the "test1" layout to be 2 or 3 times smaller than the
others
You can reduce the layout weight attribute of test1. to 0.5..
use this 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"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="6">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:background="#drawable/border"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test1" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:background="#drawable/border"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/border"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/border"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/border"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/border"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Output
I have one outer ScrollView in which there is one RecyclerView and three tabs. Every tab has a fragment and that fragment loads in corresponding tab using ViewPager but outer ScrollView does not scroll my layout. I used nested ScrollView but it also does not scroll. Maybe I did something wrong. Does any one have a suggestion? Please share with me.
Here is my xml code structure
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/parent_scroll"
android:layout_weight="1"
android:background="#color/business_price_bg"
android:focusableInTouchMode="false">
<RelativeLayout
android:id="#+id/business_detail_main_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/activity_main_search_top_main_ll"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_main_search_top_main_ll_height"
android:background="#color/location_setting_bottom_button_color"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<RelativeLayout
android:id="#+id/business_detail_activity_business_slider_main_rl"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/activity_main_search_top_main_ll">
<android.support.v7.widget.RecyclerView
android:id="#+id/business_detail_activity_slider_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</RelativeLayout>
<TextView
android:id="#+id/business_detail_activity_business_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_slider_main_rl"
android:layout_margin="10dp"
android:text=""
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/business_detail_activity_business_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_title"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text=""
android:textSize="13sp" />
<android.support.design.widget.TabLayout
android:id="#+id/business_detail_activity_tabslayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_description"
android:background="#android:color/transparent"
app:tabIndicatorColor="#color/pencilin_orange_color"
app:tabIndicatorHeight="5dp"
app:tabTextAppearance="#style/MyTabLayoutTextAppearance" />
<android.support.v4.view.ViewPager
android:id="#+id/business_detail_activity_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/business_detail_activity_tabslayout"
android:background="#android:color/white" />
</RelativeLayout>
</ScrollView>
You are going against the Android's UI Standards that's why you can never achieve your goals. Try to stick with Android UI Standards and make less complex UI.
I changed my screen Layout Structure and finally ScrollView is working
Here is solution:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">
<LinearLayout
android:id="#+id/business_detail_main_rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="#+id/activity_main_search_top_main_ll"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_main_search_top_main_ll_height"
android:layout_weight="0."
android:background="#color/location_setting_bottom_button_color"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.45"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/business_detail_activity_business_slider_main_rl"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/activity_main_search_top_main_ll">
<android.support.v7.widget.RecyclerView
android:id="#+id/business_detail_activity_slider_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scrollbars="vertical" />
</RelativeLayout>
<TextView
android:id="#+id/business_detail_activity_business_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_slider_main_rl"
android:layout_margin="10dp"
android:text=""
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/business_detail_activity_business_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_title"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text=""
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/business_preview_screen_services_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.88"
android:background="#android:color/transparent"
android:text="#string/business_preview_screen_services_btn_str"
android:textAllCaps="false" />
<View
android:id="#+id/business_preview_screen_service_btn_seperator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.12"
android:background="#color/location_setting_bottom_button_color" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/business_preview_screen_about_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.88"
android:background="#android:color/transparent"
android:text="#string/business_preview_screen_services_btn_about_btn_str"
android:textAllCaps="false" />
<View
android:id="#+id/business_preview_screen_about_btn_seperator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.13"
android:background="#color/light_gray_section_cell_seperator" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/business_preview_screen_staff_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.88"
android:background="#android:color/transparent"
android:text="#string/business_preview_screen_services_btn_staff_btn_str"
android:textAllCaps="false" />
<View
android:id="#+id/business_preview_screen_staff_btn_seperator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.13"
android:background="#color/light_gray_section_cell_seperator" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="vertical">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
I want that both elements are centered and without that stretching.
Also, it would be great if the weight was not that wide.
This is how it looks like:
Heres the code:
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#color/listColor"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/layout_item_value"
android:text="163,00"
android:textSize="18.2dp"
android:gravity="center_vertical|center_horizontal"
android:id="#+id/txtListValue"
android:textColor="#color/back"
/>
<ImageView
android:id="#+id/image_order"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:scaleX="0.4"
android:scaleY="0.4"
android:gravity="center_vertical|center_horizontal"
/>
Thank You in advance!
Its very simple, you can maintain it with the parent layout itself
<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:background="#ffffff"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/txtListValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF1493"
android:text="163,00"
android:textColor="#000000"
android:textSize="30sp" />
<ImageView
android:id="#+id/image_order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
try this layout:
<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:background="#ffffff"
android:orientation="vertical"
android:weightSum="2">
<TextView
android:id="#+id/txtListValue"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FF1493"
android:gravity="center_vertical|center_horizontal"
android:text="163,00"
android:textColor="#000000"
android:textSize="30sp" />
<ImageView
android:id="#+id/image_order"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:scaleX="0.4"
android:scaleY="0.4"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
Output:
You can use below API without weightsum...
<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:background="#ffffff"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FC226E"
android:gravity="center"
android:text="1,00"
android:textColor="#FFFFFF"
android:textSize="28sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>