I want to create a Textview with a scrollview. But it doesn't work.
It's just a Textview, which is centered-
Here is the xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="453dp"
android:layout_height="122dp"
android:gravity="center"
android:layout_marginLeft="40dp">
<ScrollView
android:id="#+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fillViewport="true">
<TextView
android:id="#+id/text1"
android:layout_width="453dp"
android:layout_height="122dp"
android:layout_gravity="left"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/black"
android:textSize="16dp"
android:maxLines="400"
/>
</ScrollView>
</LinearLayout>
fixed scroll view height
<ScrollView
android:id="#+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:scrollbars="vertical"
android:fillViewport="true">
and make height of text View to wrap_content hope this will help
You have to set Text View property simply. Don't use ScrollView
android:scrollbars="vertical"
Try removing the LinearLayout and put it into the ScrollView.
So you have ScrollView on top level and in the ScrollView you put the LinearLayout. In the LinearLayout you got the TextView.
Your LinearLayout and the TextView are the same height. So there is now way the ScrollView will scoll, because the View inside isn't taller than the ScrollView itself (which can grow to the same dimensions as the LinearLayout outside).
Related
Why the RelativeLayout doesn't wrap content? If I remove the last view which aligns to the bottom parent, it works...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="3dp"
android:layout_marginBottom="#dimen/persistent_buttons_area_height"
android:paddingBottom="8dp">
<com.xxx.ui.presentation.VerticalNestedScrollview
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="11dp"
android:clipToPadding="false"
android:overScrollMode="never">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/description"
style="#style/PresentationDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
</com.xxx.ui.presentation.VerticalNestedScrollview>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/keyline_1"
android:layout_alignParentTop="true"
android:background="#drawable/list_top_gradient_dark"/>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/keyline_1"
android:layout_alignParentBottom="true"
android:background="#drawable/list_bottom_gradient_dark"/>
</RelativeLayout>
The current result is (in red rectangle is the RelativeLayout):
So can I have a wrap content properly for this RelativeLayout?
Thank you very much guys!
How it could be, because you are using View with android:layout_alignParentBottom="true", Now what it does is that align that view to the bottom of the relative layout, now RelativeLayout height is wrap_content this won't work because android:layout_alignParentBottom="true" which force relative layout to use as much space is available.
So Possible solution can be:
add android:layout_below="#+id/scroll_view" and remove android:layout_alignParentBottom="true" from View which is at bottom of the screen.
Android newbie here.
<LinearLayout
android:layout_below="#+id/mMainTop"
android:layout_above="#+id/mMainBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// some TextView
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mSubTable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
how can I center my TableLayout vertically with reference to the remaining space left in the parent LinearLayout?
I hope someone can understand what I mean.
Try and make android:layout_gravity="center" to android:layout_gravity="center_vertical" in your TableLayout
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mSubTable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
add the following attributes to LinearLayout
android:layout_height="match_parent"
android:gravity="cneter_vertically"
You should set height the LinearLayout match_parent
I can't place my textview in RelativeLayout in the center. I added this parameters
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
but it doesn't help.
My Layout
<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:id="#+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="ru.myseolife.a99torrentsalpha2.MainActivity"
android:gravity="center"
tools:showIn="#layout/app_bar_main"
>
<TextView
android:id="#+id/nothing_found"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:text="#string/nothingfound"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<LinearLayout
android:id="#+id/linlaHeaderProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
>
<ProgressBar
android:id="#+id/progressBar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</RelativeLayout>
Anybody know what can it be? TextView is centering vertically, but horizontally it appears in the left side.
In your TextView layout_width is match_parent If you want to keep that and show it as centered you need to center the text inside the view not the TextView
So use android:gravity="center" inside your TextView or you can make TextView's width wrap_content and keep the way as it is.
Since it's a simple answer i'll tell you a trick > go to
settings > developer options > and tick Show layout boundaries then you can check the view bounds and get the idea where actually your view boundaries are !
the width of TextView should be "wrap_content"
Add
android:gravity="center"
to your textview, this will center the text since you are setting the width as match parent.
Add this:
android:gravity="center_horizontal"
I have an EditText tag inside the LinearLayout with horizontal orientation, I want to make height of my EditText as percentage of parent LinearLayout's height. How can this be achieved?
Please don't suggest layout_weight attribute as it will be used to control child elements width not height.
You could write a custom layout that resizes its children to the correct percentages, which is probably the best solution.
Or you could use layout_weight and wrap the EditText in another LinearLayout, something like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="vertical">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="one"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"/>
</LinearLayout>
Percentages within a LinearLayout are very easy.
Give your view a weight
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.25"
android:text="one"/>
</LinearLayout>
I've set the height of the two textViews to 0, but the layout_weight says to make one 50% of the LinearLayout and the other 25% the height of the layout.
I want to make a ScrollView which includes a LinearLayout:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#000000" >
<LinearLayout
android:id="#+id/mainHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal" />
</ScrollView>
Now when i add children to mainHolder I cant scroll. whats wrong?
ScrollView only supports vertical scrolling. For horizontal scrolling, use HorizontalScrollView.
Adding a horizontal linear layout in a vertical scroll view is suspicious.
For horizontal, scrolling, use a HorizontalScrollView.
Also, wrap_content size in the scrolling direction is meaningless. If it really wrapped to content size, there would be no need to scroll.
try this one
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#000000" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/mainHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal" />
</LinearLayout>
</ScrollView>
you are adding the child to the linear layout which is horizontal in orientation
so it wrap the content horizontally
change the orientation of the linear layout to vertical or try Horizontal Scrollview
<LinearLayout
android:id="#+id/mainHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="vertical" />