My layout results in the error "ScrollView can host only one direct child" when using RelativeLayout.
I want to add a scroll view after a toolbar. Everything inside the ScrollView should be scrollable vertically, but when I try this code, it results in the aforementioned error "ScrollView can host only one direct child with relativelayout".
The Layout.xml file:
<?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">
//Scroll view starts here
<include
android:id="#+id/toolbar"
layout="#layout/view_toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Most Download"
android:layout_centerVertical="true"
android:textSize="14sp"
android:textColor="#color/white"
android:paddingRight="8dp"
android:paddingLeft="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="More"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textSize="14sp"
android:textColor="#color/white"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:onClick="onOtherVideo"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_video_terbaru"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Funny Video"
android:layout_centerVertical="true"
android:textSize="14sp"
android:textColor="#color/white"
android:paddingRight="8dp"
android:paddingLeft="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="More"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textSize="14sp"
android:textColor="#color/white"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:onClick="onOtherVideoFunny"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_funny_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Religy Video"
android:layout_centerVertical="true"
android:textSize="14sp"
android:textColor="#color/white"
android:paddingRight="8dp"
android:paddingLeft="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="More"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textSize="14sp"
android:textColor="#color/white"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:onClick="onOtherReligyVideo"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_religi_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Others Video"
android:layout_centerVertical="true"
android:textSize="14sp"
android:textColor="#color/white"
android:paddingRight="8dp"
android:paddingLeft="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="More"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textSize="14sp"
android:textColor="#color/white"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:onClick="onOtherMoreVideo"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_others_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
</LinearLayout>
The Answer given by Md.ibrahim khalil is absolutely right,
Try by replacing your layout with this,
<?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">
//Scroll view starts here
<include
android:id="#+id/toolbar"
layout="#layout/view_toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Most Download"
android:textColor="#color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:onClick="onOtherVideo"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="More"
android:textColor="#color/white"
android:textSize="14sp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_video_terbaru"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Funny Video"
android:textColor="#color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:onClick="onOtherVideoFunny"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="More"
android:textColor="#color/white"
android:textSize="14sp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_funny_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Religy Video"
android:textColor="#color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:onClick="onOtherReligyVideo"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="More"
android:textColor="#color/white"
android:textSize="14sp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_religi_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey_868686">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Others Video"
android:textColor="#color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:onClick="onOtherMoreVideo"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="More"
android:textColor="#color/white"
android:textSize="14sp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_others_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</LinearLayout>
take a relative layout or linear layout then put all view into it and then wrap this relative layout with scroll view
your problem will be solved.
Related
I've created a preference UI but the thing is I can't let the bottommost child view to be displayed on the device. It keeps discarding the bottommost view. Though this query is similar to one I found in the query list yet the problem I'm facing left me with no debugging ways or I'm missing some serious property.
My code is:
The Bottom TextView which I finally wrapped inside a relativeView is the part which is discarded.
To ,y wonder I changed to LinearLayout from Relative built I guess It might have some issues as well..
But the most important query is that it doesn't scroll till the end of the Activity.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Preferences">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/colorPrimary"
android:id="#+id/header"
enter code here
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/back_key"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_prefer"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="#string/activity_name"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="18sp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/wrapper_scroll"
android:layout_below="#id/header"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scroll_horizontal"
android:fillViewport="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp"
android:id="#+id/rel_scroll"
android:layout_marginBottom="10dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_age_layout"
android:layout_marginBottom="5dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:id="#+id/age_text"
android:text="#string/age"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:layout_alignParentRight="true"
android:text="18-26"
android:textStyle="bold"
android:textSize="14sp"
android:textColor="#color/black"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_age_pref"
android:layout_below="#id/rel_age_layout"
android:text="#string/age_prefer"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:layout_below="#id/rel_age_layout"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_interest_layout"
android:layout_marginBottom="5dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:id="#+id/interested_in_text"
android:text="#string/interested_in"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_below="#id/interested_in_text"
android:text="#string/men"
android:textSize="14sp"
android:textColor="#color/black"
android:id="#+id/men"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_below="#id/men"
android:layout_marginTop="10dp"
android:text="#string/women"
android:textSize="14sp"
android:textColor="#color/black"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/interested_pref"
android:layout_below="#id/rel_interest_layout"
android:text="#string/interested_prefer"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="38dp"
android:layout_below="#id/rel_interest_layout"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_alerts_layout"
android:layout_marginBottom="5dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:id="#+id/alerts_mode"
android:text="#string/alerts"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_below="#id/alerts_mode"
android:text="#string/sound"
android:textSize="14sp"
android:layout_marginBottom="14dp"
android:textColor="#color/black"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sound_prefer"
android:layout_below="#id/rel_alerts_layout"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:layout_marginBottom="5dp"
android:layout_below="#id/rel_alerts_layout"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_matchmaker_layout"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:id="#+id/matchmaker_text"
android:text="#string/matchmaker"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="18dp"
android:layout_below="#id/matchmaker_text"
android:text="#string/hide_my_prof"
android:textSize="14sp"
android:textColor="#color/black"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/matchmaker_prefer"
android:text="#string/matchmaker_prefer"
android:layout_below="#id/rel_matchmaker_layout"
android:textSize="12sp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="38dp"
android:layout_below="#id/rel_matchmaker_layout"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_whitelist_layout"
android:layout_marginBottom="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:id="#+id/whitelist_text"
android:text="#string/whitelist"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:layout_alignParentRight="true"
android:text="#string/go"
android:padding="10dp"
android:background="#drawable/edittext_rectangle_border"
android:textStyle="bold"
android:textSize="14sp"
android:textColor="#color/black"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rel_whitelist_layout"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:text="#string/whitelist_prefer"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
Here's the screenshot:
Try changing the height of the ScrollView from match_parent to wrap_content:
<ScrollView
...
android:layout_height="wrap_content"
... >
I tried your xml and this worked.
Add this to your last TextView
android:layout_margin="18dp"
Your last element will be:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rel_whitelist_layout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_margin="18dp"
android:text="#string/whitelist_prefer"/>
</RelativeLayout>
I want my one textbox to only wrap content till the beginning of the next textbox.
Screenshot now:
and how I want it:
I was thinking I could set the width but it wouldn't display correctly on different size screens, I want it to end there so I can have it ellipses if the content goes out of the area.
Please help!
Layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cardView_item_assesment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:clickable="true"
android:focusable="true"
app:cardCornerRadius="4dp"
app:cardElevation="4dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView_title"
android:layout_width="285dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:textColor="#color/colorPrimaryDark"
android:textSize="30sp"
tools:text="PlaceHolder" />
<TextView
android:id="#+id/textView_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:textColor="#color/colorPrimaryDark"
android:textSize="15sp"
android:layout_margin="5dp"
tools:text="2018/09/02" />
<TextView
android:id="#+id/textView_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView_date"
android:layout_alignParentEnd="true"
android:textColor="#color/colorPrimaryDark"
android:textSize="15sp"
android:layout_margin="5dp"
tools:text="09:00" />
<TextView
android:id="#+id/textView_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/editText_achieved"
android:layout_below="#+id/textView_title"
android:textColor="#color/colorPrimaryDark"
android:layout_alignBaseline="#id/editText_achieved"
android:textSize="20sp"
android:layout_margin="5dp"
tools:text="Total: 100" />
<android.support.v7.widget.AppCompatEditText
android:id="#+id/editText_achieved"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textView_title"
android:maxLines="1"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp"
tools:text="Result: 50" />
<TextView
android:id="#+id/textView_contribution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView_total"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp"
android:layout_margin="5dp"
tools:text="Weight: 25%"/>
<TextView
android:id="#+id/txtID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible" />
</RelativeLayout>
add:
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/textView_date"
and set width to wrap_content in your first TextView
<TextView
android:id="#+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_toLeftOf="#+id/textView_date"
android:layout_alignParentLeft="true"
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:textColor="#color/colorPrimaryDark"
android:textSize="30sp"
tools:text="PlaceHolder" />
result
Use LinearLayout for this...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text"
android:layout_weight=".4"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="12/12/1212"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="9:00"/>
</LinearLayout>
</LinearLayout>
Result:
I saw so many people ask the same question in here, but I still cannot find the reason why my scrollview doesn't work.
Here is my Layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_upload"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:fillViewport="true"
tools:context="com.example.daniw.traekle.upload">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tv_itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Name"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginBottom="5dp"/>
<EditText
android:id="#+id/et_itemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:layout_marginBottom="5dp"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="Book ISBN(option)"
android:id="#+id/tv_bISBN"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000" />
<EditText
android:id="#+id/et_ISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:textColor="#000000"
android:text="test"/>
<TextView
android:id="#+id/tv_itemPrice"
android:text="Price"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#000000"
android:layout_marginBottom="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/et_itemPrice"
android:text="Test"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"/>
<TextView
android:id="#+id/tv_itemDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Description"
android:textSize="20sp"
android:textColor="#000000"
android:textStyle="bold"
android:layout_marginBottom="5dp"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/inputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="600"
app:counterOverflowTextAppearance="#style/MyOverflowText">
<EditText
android:id="#+id/et_itemDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Test"
android:maxLength="600"
android:textColor="#000000"/>
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Choose Image"
android:id="#+id/b_chooseImage"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/itemImage"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Post Item"
android:id="#+id/bPost"/>
</LinearLayout>
</ScrollView>
That is so weird, because I finished other layout use the scrollview it's work fine, but in this activity the scrollview doesn't even show in preview.
There no scroll
You have your LinearLayout height set to fill_parent which is deprecated but is the same thing is match_parent instead your LinearLayout height should be set to wrap_content.
The reason is that your LinearLayout has the same exact height as the ScrollView so there is no need to scroll. If you set it to wrap_content the LinearLayout can have a height larger then the ScrollView which will scroll to show what is outside of ScrollViews bounds
Try this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_upload"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:fillViewport="true"
tools:context="com.example.daniw.traekle.upload">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Name"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginBottom="5dp"/>
<EditText
android:id="#+id/et_itemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:layout_marginBottom="5dp"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="Book ISBN(option)"
android:id="#+id/tv_bISBN"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000" />
<EditText
android:id="#+id/et_ISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:textColor="#000000"
android:text="test"/>
<TextView
android:id="#+id/tv_itemPrice"
android:text="Price"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#000000"
android:layout_marginBottom="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/et_itemPrice"
android:text="Test"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"/>
<TextView
android:id="#+id/tv_itemDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Description"
android:textSize="20sp"
android:textColor="#000000"
android:textStyle="bold"
android:layout_marginBottom="5dp"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/inputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="600"
app:counterOverflowTextAppearance="#style/MyOverflowText">
<EditText
android:id="#+id/et_itemDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Test"
android:maxLength="600"
android:textColor="#000000"/>
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Choose Image"
android:id="#+id/b_chooseImage"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_margin="5dp"
android:paddingBottom="16dp"
android:scaleType="fitXY"
android:id="#+id/itemImage"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Post Item"
android:id="#+id/bPost"/>
</LinearLayout>
</ScrollView>
Just realize how stupid am I , i finish fixed this problem.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_upload"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:fillViewport="true"
tools:context="com.example.daniw.traekle.upload">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Choose Image"
android:id="#+id/b_chooseImage"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="5dp"
android:layout_marginBottom="5dp"
android:paddingBottom="50dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
android:scaleType="fitXY"
android:id="#+id/itemImage"/>
<TextView
android:id="#+id/tv_itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Name"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginBottom="5dp"/>
<EditText
android:id="#+id/et_itemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:layout_marginBottom="5dp"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="Book ISBN(option)"
android:id="#+id/tv_bISBN"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000" />
<EditText
android:id="#+id/et_ISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:textColor="#000000"
android:text="test"/>
<TextView
android:id="#+id/tv_itemPrice"
android:text="Price"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#000000"
android:layout_marginBottom="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/et_itemPrice"
android:text="Test"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"/>
<TextView
android:id="#+id/tv_itemDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Description"
android:textSize="20sp"
android:textColor="#000000"
android:textStyle="bold"
android:layout_marginBottom="5dp"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/inputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="600"
app:counterOverflowTextAppearance="#style/MyOverflowText">
<EditText
android:id="#+id/et_itemDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Test"
android:maxLength="600"
android:textColor="#000000"/>
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Post Item"
android:id="#+id/bPost"/>
</LinearLayout>
</ScrollView>
Now this layout working fine
I am trying to add three text views as follows, but I could not able to achieve it. I want A to be on the left side, and the other two texviews to be right side.
Here is what I get:
Here is my current implementation
<RelativeLayout
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:background="#363636">
<TextView
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="A"
android:textColor="#android:color/white"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:textSize="16sp"
android:fontFamily="sans-serif-medium" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:id="#+id/innerLayout">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:text="B "
android:textSize="16sp"
android:textColor="#android:color/white"
android:paddingRight="8dp" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:text="C "
android:textSize="16sp"
android:textColor="#android:color/white"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:paddingLeft="8dp"
android:paddingRight="8dp" />
</RelativeLayout>
</RelativeLayout>
use this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:id="#+id/A"
android:text="aaaaaaa"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:id="#+id/C"
android:text="ccccccc"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/C"
android:id="#+id/B"
android:text="bbbbbbb"
android:padding="8dp"/>
</RelativeLayout>
Change the xml like this ,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#363636"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<TextView android:background="#458765"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:fontFamily="sans-serif-medium"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:text="A"
android:textColor="#android:color/white"
android:textSize="16sp" />
<RelativeLayout
android:id="#+id/innerLayout"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true">
<TextView android:background="#458765"
android:id="#+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="B"
android:textColor="#android:color/white"
android:textSize="16sp" />
<TextView android:layout_marginLeft="5dp" android:background="#458765"
android:layout_toRightOf="#id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="C"
android:textColor="#android:color/white"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
I have a problem, I have a long layout so I need it will be scrollable. But I need two listview in it. I have made using linearlayout and in forcycle I add a items in it. But I have lost all functions what listview offers and I want to use them.
Do anybody knows, how looks like "events" view in facebook app? It looks like there are a lot of listviews (birthdays, events, ...) and whole view is scrollable. I need something like this.
Thank you for ansver. :)
EDIT: There is my xml (There are two LinearLayouts: #+id/passengersList and #+id/discussionList and I want use ListViews instead):
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/travelDetailScroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#f8ffe1"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingRight="5dp"
android:paddingLeft="5dp">
<TextView
android:id="#+id/travelId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/waypoints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:textColor="#333333"
android:textSize="16sp" />
<ImageView
android:id="#+id/travelMap"
android:layout_width="70dp"
android:layout_height="70dp"
android:paddingLeft="0dp"
android:paddingTop="0dp"
android:paddingRight="8dp"
android:layout_below="#+id/waypoints"
android:contentDescription="#string/travel_detail" />
<TextView
android:id="#+id/driver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/waypoints"
android:layout_toRightOf="#+id/travelMap"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:id="#+id/car"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/driver"
android:layout_toRightOf="#+id/travelMap"
android:paddingBottom="10dp"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/waypoints"
android:textColor="#aaaaaa"
android:layout_alignParentRight="true"
android:textSize="14sp" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/date"
android:layout_alignParentRight="true"
android:textColor="#aaaaaa"
android:textSize="14sp" />
<ImageView
android:id="#+id/icon_price"
android:layout_below="#+id/car"
android:layout_toRightOf="#+id/travelMap"
android:layout_width="20dp"
android:layout_height="20dp"
android:paddingLeft="0dp"
android:paddingTop="0dp"
android:paddingRight="6dp"
android:contentDescription="#string/travel_price" />
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/car"
android:layout_toRightOf="#+id/icon_price"
android:paddingRight="40dp"
android:textColor="#333333"
android:textSize="14sp" />
<ImageView
android:id="#+id/icon_seats"
android:layout_below="#+id/car"
android:layout_toRightOf="#+id/price"
android:layout_gravity="center|center_vertical"
android:layout_width="20dp"
android:layout_height="20dp"
android:paddingLeft="0dp"
android:paddingTop="0dp"
android:paddingRight="6dp"
android:contentDescription="#string/travel_seats" />
<TextView
android:id="#+id/seats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/car"
android:layout_toRightOf="#+id/icon_seats"
android:layout_gravity="center|center_vertical"
android:paddingBottom="10dp"
android:textColor="#333333"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/header"
android:layout_centerHorizontal="true" >
<RelativeLayout
android:id="#+id/buttonsLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_travel_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/travel_login" />
<Button
android:id="#+id/btn_travel_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/travel_logout"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/buttonsRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="8dp"
android:layout_toRightOf="#+id/buttonsLeft" >
<Button
android:id="#+id/btn_travel_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/travel_edit"
android:visibility="gone" />
<Button
android:id="#+id/btn_travel_watch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/travel_watch"
android:visibility="gone" />
<Button
android:id="#+id/btn_travel_unwatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/travel_unwatch"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/buttons"
android:paddingTop="10dp">
<TextView
android:id="#+id/driverTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:paddingBottom="2dp"
android:textColor="#333333"
android:textSize="14sp"
android:text="#string/driver_title" />
<RelativeLayout
android:id="#+id/driverInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/driverTitle"
android:background="#f8ffe1">
<ImageView
android:id="#+id/driverPhoto"
android:layout_width="65dp"
android:layout_height="65dp"
android:paddingRight="8dp"
android:paddingLeft="0dp"
android:paddingTop="0dp" />
<TextView
android:id="#+id/driverName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:layout_toRightOf="#+id/driverPhoto"
android:textColor="#333333"
android:textSize="16sp" />
<TextView
android:id="#+id/driverEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/driverName"
android:layout_toRightOf="#+id/driverPhoto"
android:textColor="#999999"
android:textSize="14sp" />
<TextView
android:id="#+id/driverPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/driverEmail"
android:layout_toRightOf="#+id/driverPhoto"
android:paddingBottom="10dp"
android:textColor="#333333"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/passengersInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/driverInfo"
android:paddingTop="10dp">
<TextView
android:id="#+id/passengersTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:paddingTop="7dp"
android:paddingBottom="2dp"
android:textColor="#333333"
android:textSize="14sp"
android:text="#string/passengers_title" />
<TextView
android:id="#+id/noPassengers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/passengersTitle"
android:textColor="#333333"
android:textSize="14sp"
android:text="#string/no_passengers"
android:visibility="gone" />
<LinearLayout
android:id="#+id/passengersList"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#+id/passengersTitle"
android:orientation="vertical" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/discussion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/passengersInfo"
android:paddingTop="10dp">
<TextView
android:id="#+id/discussionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="2dp"
android:textColor="#333333"
android:textSize="14sp"
android:text="#string/discussion_title" />
<LinearLayout
android:id="#+id/discussionList"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#+id/discussionTitle"
android:orientation="vertical" />
<TextView
android:id="#+id/addMessageLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="7dp"
android:paddingBottom="2dp"
android:textColor="#8ec83e"
android:textSize="14sp"
android:layout_below="#+id/discussionList"
android:layout_centerHorizontal="true"
android:text="#string/add_message" />
<LinearLayout android:id="#+id/newMessageLayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="#+id/addMessageLink"
android:orientation="horizontal"
android:paddingTop="7dp"
android:paddingBottom="2dp"
android:visibility="gone">
<EditText
android:id="#+id/newMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#333333"
android:textSize="14sp"
android:hint="#string/new_message"
android:layout_weight="3" />
<Button
android:id="#+id/addMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#333333"
android:textSize="14sp"
android:hint="#string/send_message"
android:layout_gravity="right"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/waypointsDetail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/discussion"
android:paddingTop="10dp">
<TextView
android:id="#+id/waypointsTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="2dp"
android:textColor="#333333"
android:textSize="14sp"
android:text="#string/waypoints_title" />
<LinearLayout android:id="#+id/waypointsList"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="#+id/waypointsTitle"
android:orientation="vertical" />
<TextView
android:id="#+id/waypointsSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="2dp"
android:textColor="#333333"
android:textSize="14sp"
android:layout_below="#+id/waypointsList" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>