I want to create two rows of
TextView .... CustomeSwitvchView
CustomeSwitchView ... TextView
However, using this xml doesn't yield the expected order.
both rows show only the CustomeSwitchView aligned to right, with no text shown.
<LinearLayout style="#style/settingsSection">
<RelativeLayout
android:id="#+id/settingsSwitchLayoutRtl"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:id="#+id/settingsSwitchRtl" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/settingsSwitchRtl"
android:layout_centerVertical="true"
android:textColor="#00FF00"
android:text="My Settings1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/settingsSwitchLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:id="#+id/settingsSwitch" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/settingsSwitch"
android:layout_centerVertical="true"
android:textColor="#00FF00"
android:text="My Settings2" />
</RelativeLayout>
</LinearLayout>
How can I fix this?
Try this:
<LinearLayout style="#style/settingsSection">
<RelativeLayout
android:id="#+id/settingsSwitchLayoutRtl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:layout_alignParentTop="true"
android:id="#+id/settingsSwitchRtl" />
<TextView
android:id="#+id/switch_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/settingsSwitchRtl"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:textColor="#00FF00"
android:text="My Settings1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/settingsSwitchLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:id="#+id/settingsSwitch" />
<TextView
android:id="#+id/switch_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/settingsSwitch"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:textColor="#00FF00"
android:text="My Settings2" />
</RelativeLayout>
</LinearLayout>
Try this..
<LinearLayout style="#style/settingsSection">
<RelativeLayout
android:id="#+id/settingsSwitchLayoutRtl"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection"
android:background="#drawable/item_selector_single"
android:layout_alignParentRight="true"
android:paddingLeft="85dp"
android:id="#+id/settingsSwitchRtl" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:textColor="#00FF00"
android:text="My Settings1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/settingsSwitchLayout"
android:layout_width="wrap_content"
android:layout_below="#+id/settingsSwitchLayoutRtl"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection"
android:layout_alignParentLeft="true"
android:paddingRight="85dp"
android:background="#drawable/item_selector_single"
android:id="#+id/settingsSwitch" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textColor="#00FF00"
android:text="My Settings2" />
</RelativeLayout>
</LinearLayout>
I am not sure but u can try it
<LinearLayout style="#style/settingsSection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation = "vertical">
<RelativeLayout
android:id="#+id/settingsSwitchLayoutRtl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:layout_alignParentRight="true"
android:id="#+id/settingsSwitchRtl" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/settingsSwitchRtl"
android:layout_centerVertical="true"
android:textColor="#00FF00"
android:text="My Settings1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/settingsSwitchLayout"
android:layout_width="match_parent"
android:layout_below="#+id/settingsSwitchLayoutRtl"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:layout_alignParentLeft="true"
android:id="#+id/settingsSwitch" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/settingsSwitch"
android:layout_centerVertical="true"
android:textColor="#00FF00"
android:text="My Settings2" />
</RelativeLayout>
</LinearLayout>
Related
Hi i had to make a layout with card with recyclerview so for that i set an image as a background to linear layout but now i'm unable to center crop that image
My problem is that i cannot use imageview because using that the height of card increases as well and i don't want that so please if someone can assit me..
my xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/primary_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="15dp"
app:cardCornerRadius="115dp">
<ImageView
android:id="#+id/background_image_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:visibility="gone" />
<LinearLayout
android:id="#+id/background_image"
android:layout_width="match_parent"
android:layout_height="210dp"
android:background="#drawable/club1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:src="#drawable/ellipse" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="John Doe"
android:textColor="#color/White"
android:textSize="15sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="checked in to"
android:textColor="#color/White"
android:textSize="10sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="W south"
android:textColor="#color/White"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="9dp"
android:text="beach mumbai"
android:textColor="#color/White"
android:textSize="15sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/fifth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/second_text"
android:layout_toRightOf="#+id/fourth_text"
android:text="30 mins ago."
android:textColor="#color/White"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="85dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/sixth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:padding="10dp"
android:text="reply to abc............"
android:textColor="#color/White" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/favourite_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ic_favorite_border_black_24dp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/seventh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:text="40 likes"
android:textColor="#color/White" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
You can't center crop a background image of linear layout,
But you can achieve the same using these changes:
Replace you LinearLayout with RelativeLayout
Place a ImageView as a first child inside relative layout and use property for center crop.
<RelativeLayout
android:id="#+id/background_image"
android:layout_width="match_parent"
android:layout_height="210dp"
android:orientation="vertical">
<ImageView
android:scaleType="centerCrop"
android:src="#drawable/club1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
.....
......
</RelativeLayout>
If you Want to control The Image View Scale
you need to put it in ImageView As Src Not Background
You can use Frame layout To Achieve it
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/primary_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="15dp"
app:cardCornerRadius="115dp">
<ImageView
android:id="#+id/background_image_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:visibility="gone" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="210dp">
<ImageView
android:layout_width="match_parent"
android:src="#mipmap/ic_launcher"
android:layout_height="match_parent" />
<LinearLayout
android:id="#+id/background_image"
android:layout_width="match_parent"
android:layout_height="210dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/profile_image"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:src="#drawable/playstore_icon" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="#+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="John Doe"
android:textSize="15sp" />
<TextView
android:id="#+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="checked in to"
android:textSize="10sp" />
<TextView
android:id="#+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="W south"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="9dp"
android:text="beach mumbai"
android:textSize="15sp" />
<TextView
android:id="#+id/fifth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/second_text"
android:layout_toRightOf="#+id/fourth_text"
android:text="30 mins ago."
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="85dp">
<TextView
android:id="#+id/sixth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:padding="10dp"
android:text="reply to abc............"
android:textColor="#color/white" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/favourite_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ic_close" />
<TextView
android:id="#+id/seventh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:text="40 likes"
android:textColor="#color/white" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</android.support.v7.widget.CardView>
CenterCrop logic is baked inside ImageView. The correct solution is to extract it into a Drawable which wraps another Drawable and centerCrops it.
If you use CoordinatorLayout, then just to put your ImageView with centerCrop parameter to top.
<CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:scaleType="centerCrop"
android:background="#drawable/background_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp">
<include layout="#layout/header_main" />
<TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#android:color/white"
android:background="#drawable/white_border_background"
app:tabIndicatorHeight="3dp"/>
</AppBarLayout>
<ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</CoordinatorLayout>
I want to have a layout exactly similar to one below in image.
I've tried the below code but it is not coming.
Can someone help me in getting this layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<TextView
android:id="#+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Ali Connors"
android:textSize="12sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstLine"
android:gravity="center_vertical"
android:text="Brunch this weekend?"
android:textSize="16sp" />
<TextView
android:gravity="right"
android:id="#+id/rightTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="15m"
android:textSize="16sp" />
</RelativeLayout>
try the following:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="#ED262A" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp">
<TextView
android:id="#+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="26dp"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Ali Connors"
android:textSize="18sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstLine"
android:gravity="center_vertical"
android:text="Brunch this weekend?"
android:textSize="15sp" />
<TextView
android:id="#+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/secondLine"
android:drawablePadding="6dp"
android:drawableRight="#android:drawable/star_off"
android:gravity="center_vertical"
android:text="I will be in the place"
android:textColor="#A4A18E"
android:textSize="14sp" />
<TextView
android:id="#+id/rightTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentRight="true"
android:gravity="top|right"
android:text="15m"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
Try this.
<TextView
android:text="15m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/rightTime"
android:textSize="16sp"/>
Design your Layout 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="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="#FF4081" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="#+id/rightTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="15m"
android:textSize="14sp"
android:textColor="#727272"/>
<TextView
android:id="#+id/firstLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/rightTime"
android:layout_marginRight="8dp"
android:maxLines="1"
android:ellipsize="end"
android:text="Ali Connors"
android:textSize="16sp"
android:textColor="#000000"/>
<TextView
android:id="#+id/secondLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstLine"
android:layout_marginTop="2dp"
android:text="Brunch this weekend?"
android:textSize="16sp"
android:textColor="#000000"
android:maxLines="1"
android:ellipsize="end" />
<ImageView
android:id="#+id/image_star"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="#id/secondLine"
android:layout_alignParentRight="true"
android:background="#android:drawable/star_big_off" />
<TextView
android:id="#+id/thirdLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/secondLine"
android:layout_toLeftOf="#id/image_star"
android:layout_marginTop="4dp"
android:layout_marginRight="16dp"
android:text="I will be in your neighborhood doing some errands....."
android:textColor="#727272"
android:textSize="14sp"
android:maxLines="1"
android:ellipsize="end" />
</RelativeLayout>
</LinearLayout>
Output:
I have been getting the above error for quite some time. Upon a lot of prodding around, I've come to the conclusion that its my xml itself which is causing this issue. I have commented ALL of my code in my java file and tried to load JUST THE LAYOUT. Even then the warning keeps popping up. I am herein attaching my xml file, hoping someone can shed some light on this. I would like to know what are the "heavy duty" work being performed which is causing my app to "skip frames".
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:clipToPadding="false"
android:id="#+id/coordinator"
android:background="#drawable/back_1"
tools:context="com.avantaritech.flipa.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/first_bar">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_white_24dp"
android:contentDescription="#string/overflow_home"
android:id="#+id/nav_button"/>
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/fill"
android:layout_alignParentTop="true"
android:id="#+id/logo"
android:layout_centerHorizontal="true" />
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sync_green"
android:id="#+id/sync_button"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"/>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/_1sdp"
android:layout_margin="#dimen/_5sdp"
android:background="#android:color/darker_gray"
android:layout_below="#+id/logo"
android:id="#+id/view" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/view"
android:id="#+id/mega_relative"
android:layout_alignEnd="#+id/view">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/viewpager_holder_first"
android:layout_alignParentStart="true"
android:layout_marginTop="#dimen/_10sdp"
android:layout_alignParentTop="true">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_marginTop="#dimen/_1sdp"
android:id="#+id/viewpager_first"
android:layout_height="#dimen/_225sdp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
</android.support.v4.view.ViewPager>
<me.relex.circleindicator.CircleIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="#dimen/_25sdp"
android:layout_below="#+id/viewpager_first"/>
</RelativeLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="#dimen/_110sdp"
android:layout_below="#+id/viewpager_holder_first"
android:scrollbars="none"
android:overScrollMode="always"
android:id="#+id/horizontalScrollView">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/_10sdp"
>
<FrameLayout
android:layout_width="#dimen/_100sdp"
android:layout_height="match_parent"
android:background="#color/textbox_home">
<ImageView
android:layout_width="#dimen/_30sdp"
android:layout_height="#dimen/_30sdp"
android:src="#drawable/hr"
android:id="#+id/hr_image_home"
android:layout_margin="#dimen/_5sdp"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heart Rate"
android:fontFamily="sans-serif-light"
android:id="#+id/hr_text_home"
android:layout_marginStart="#dimen/_10sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_gravity="end|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:id="#+id/home_hr"
android:textSize="35sp"
android:textStyle="bold"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BPM"
android:textColor="#color/skin_v1"
android:layout_marginTop="#dimen/_75sdp"
android:layout_marginBottom="#dimen/_5sdp"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
<FrameLayout
android:layout_width="#dimen/_100sdp"
android:layout_height="match_parent"
android:elevation="#dimen/_10sdp"
android:layout_marginStart="#dimen/_15sdp"
android:background="#color/textbox_home">
<ImageView
android:layout_width="#dimen/_30sdp"
android:layout_height="#dimen/_30sdp"
android:src="#drawable/steps"
android:id="#+id/steps_image_home"
android:layout_margin="#dimen/_5sdp"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:id="#+id/home_steps"
android:textSize="30sp"
android:textStyle="bold"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="STEPS"
android:textColor="#color/skin_v1"
android:layout_marginTop="#dimen/_75sdp"
android:layout_marginBottom="#dimen/_5sdp"
android:layout_gravity="center_horizontal|bottom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Steps"
android:fontFamily="sans-serif-light"
android:id="#+id/steps_text_home"
android:layout_marginEnd="#dimen/_5sdp"
android:layout_marginStart="#dimen/_30sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_gravity="center_horizontal|top" />
</FrameLayout>
<FrameLayout
android:layout_width="#dimen/_100sdp"
android:layout_height="match_parent"
android:elevation="#dimen/_10sdp"
android:layout_marginStart="#dimen/_25sdp"
android:background="#color/textbox_home">
<ImageView
android:layout_width="#dimen/_30sdp"
android:layout_height="#dimen/_30sdp"
android:src="#drawable/dist"
android:id="#+id/dist_image_home"
android:layout_margin="#dimen/_5sdp"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:id="#+id/dist_textview_home"
android:textSize="30sp"
android:textStyle="bold"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="METERS"
android:id="#+id/dist_unit"
android:textColor="#color/skin_v1"
android:layout_marginTop="#dimen/_75sdp"
android:layout_marginBottom="#dimen/_5sdp"
android:layout_gravity="center_horizontal|bottom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance"
android:fontFamily="sans-serif-light"
android:id="#+id/dist_text_home"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginStart="#dimen/_15sdp"
android:layout_gravity="center_horizontal|top" />
</FrameLayout>
<FrameLayout
android:layout_width="#dimen/_100sdp"
android:layout_height="match_parent"
android:elevation="#dimen/_10sdp"
android:layout_marginStart="#dimen/_30sdp"
android:background="#color/textbox_home">
<ImageView
android:layout_width="#dimen/_30sdp"
android:layout_height="#dimen/_30sdp"
android:src="#drawable/pace"
android:id="#+id/pace_image_home"
android:layout_margin="#dimen/_5sdp"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:id="#+id/pace_textview_home"
android:textSize="30sp"
android:textStyle="bold"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="STEPS/MIN"
android:textColor="#color/skin_v1"
android:layout_marginTop="#dimen/_75sdp"
android:layout_marginBottom="#dimen/_5sdp"
android:layout_gravity="center_horizontal|bottom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avg. Pace"
android:fontFamily="sans-serif-light"
android:id="#+id/pace_text_home"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginStart="#dimen/_10sdp"
android:layout_gravity="center_horizontal|top" />
</FrameLayout>
<FrameLayout
android:layout_width="#dimen/_100sdp"
android:layout_height="match_parent"
android:elevation="#dimen/_10sdp"
android:layout_marginStart="#dimen/_30sdp"
android:background="#color/textbox_home">
<ImageView
android:layout_width="#dimen/_20sdp"
android:layout_height="#dimen/_20sdp"
android:src="#drawable/cal"
android:id="#+id/cal_avg_image_home"
android:layout_margin="#dimen/_5sdp"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:id="#+id/cal_avg_textview_home"
android:textSize="30sp"
android:textStyle="bold"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="KCAL/MIN"
android:textColor="#color/skin_v1"
android:layout_marginTop="#dimen/_75sdp"
android:layout_marginBottom="#dimen/_5sdp"
android:layout_gravity="center_horizontal|bottom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avg. KCAL"
android:fontFamily="sans-serif-light"
android:id="#+id/kcal_text_home"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginStart="#dimen/_10sdp"
android:layout_gravity="center_horizontal|top" />
</FrameLayout>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/mega_relative"
android:layout_toEndOf="#+id/nav_button"
android:layout_alignParentStart="true">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
app:fabSize="normal"
android:id="#+id/workout_start"
android:src="#drawable/run"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Hoping this is a simple one.
I have a layout that uses a scrollview. This was fine until I wanted to put an image and textview above it then have the scrollview with my edittexts below it.
At the moment I'm getting the following errors:
01-22 20:13:32.228: E/AndroidRuntime(275): FATAL EXCEPTION: main
01-22 20:13:32.228: E/AndroidRuntime(275): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.addAppointment}: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_width attribute.
I have tried to change the scroll views width attribute (which i believe that error is pointing too) with no luck.
Here's my XML. Can anyone see what I'm doing wrong?:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="84dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/viewcon" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="75dp"
android:gravity="center"
android:text="Appointments"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp" />
</LinearLayout>
\\ERROR: On width attribute
<ScrollView
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="Name:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<DatePicker
android:id="#+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppCom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Appointment Date Alarm:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ToggleButton
android:id="#+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:textOff="Alarm Off"
android:textOn="Alarm On" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Appointment"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnAddAppointment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />
</ScrollView>
</LinearLayout>
EDIT:
You can only set one child layout to a ScrollView. I don't know why it's showing you that you didn't set android:layout_width attribute, but your problem is definitely that you have multiple child views in your ScrollView.
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="84dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/viewcon" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="75dp"
android:gravity="center"
android:text="Appointments"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<DatePicker
android:id="#+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppCom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Appointment Date Alarm:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ToggleButton
android:id="#+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:textOff="Alarm Off"
android:textOn="Alarm On" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Appointment"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnAddAppointment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I've already tried to align the smallprogressbar with the textview putting them into a linear layout but it doesn't work. Tryed with android:layout_gravity="left" but it crashes.
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_1"
android:textColor="#33b5e5"
android:textSize="16dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tvNumberWaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/calibration_2"
android:textColor="#FFFFFF"
android:textSize="18dp" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tvIntervalWaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/calibration_3"
android:textColor="#FFFFFF"
android:textSize="18dp" />
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/bSetValues"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_5" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_6" />
</ScrollView>
</LinearLayout>
Code updated to match your answer.
I put the whole code to show what I have.
Change this line:
android:orientation="vertical"
to this:
android:orientation="horizontal"
Without seeing the rest of your source, I don't know if that will mess up other parts of your layout, so you'll probably want to wrap the TextView and ProgressBar in their own LinearLayout.
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_1"
android:textColor="#33b5e5"
android:textSize="16dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvNumberWaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/calibration_2"
android:textColor="#FFFFFF"
android:textSize="18dp" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvIntervalWaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/calibration_3"
android:textColor="#FFFFFF"
android:textSize="18dp" />
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/bSetValues"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_5" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_6" />
</ScrollView>
</LinearLayout>