I can't find a solution for that. I managed to solve the problem of NOT overlapping the scrollview with my button+textview at the bottom, but I still can't manage to have the scrollview starting from the top of the screen rather than from just above my button.
Note that even the bottom linearlayout (button+textview) isn't exactly what I wanted. I can't find a way to have everything positioned correctly.
Eclipse is not helping either, since the text view of the xml keeps changing under my mouse, making it extremely annoying. I had to open an external editor to edit it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top" >
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<TextView
android:id="#+id/text_phrase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="#string/play" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/LinearLayout2"
android:layout_alignParentLeft="true"
android:layout_marginBottom="18dp" >
<LinearLayout
android:id="#+id/layout_player_checkboxes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:orientation="vertical" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
</LinearLayout>
</ScrollView>
if you add android:layout_alignParentTop="true" and android:layout_weight="1" to your scrollview while leaving the rest of what you have already, it should start at the top and fill the screen below until it comes to linearlayout2. (Same applies if you decide to switch to a listview as rajesh.adhi suggested)
Oh, you seem to be missing a </RelativeLayout> there too.
Related
I'm searching for a solution to set up multiple rows in a scrollview.
I have 15 buttons (3*5) and want to scroll to the right so there are another 15 buttons.
What I already got: all buttons are in one huge row ( at least, scrolling iself worked ).
Then I tried to set the HorizontalScrollView on the highest layer (line #1 in XML) and after that a LinearLayout that contains 3 further LinearLayouts so the tree looks like this:
<HorizontalScrollView
<LinearLayout
<LinearLayout
(buttonABCDEF)
</LinearLayout>
<LinearLayout
(button01234)
</LinearLayout>
<LinearLayout
(button56789)
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
What I get then is a (~80x80) rectangle (the linear layout in the ScrollView) that shows a text (the first view in my layout) and a button (buttonA - the first one) that is so stemmed (by whatever) that every character is written into a new line. (The amount of letters= amount of lines= button height). This isn't scrollable at all.
I'm trying to post only the code that is relevant. Note: that android:layout stuff is not important for you since it is not working in a linear layout:
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/horizontalScrollView1"
tools:context=".MainActivity"
android:background="#android:color/black"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation='vertical' >
android:layout_width="9dp"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_width="9dp"
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:textColor="#android:color/white"
android:text="text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/buttonA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/buttonB"
android:layout_toRightOf="#+id/textView1"
android:width="70dp"
android:text="A" />
<Button
android:id="#+id/buttonE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttonD"
android:layout_alignBottom="#+id/buttonD"
android:layout_toRightOf="#+id/buttonD"
android:width="70dp"
android:text="B" />
<Button
android:id="#+id/buttonF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttonE"
android:layout_alignBottom="#+id/buttonE"
android:layout_toRightOf="#+id/buttonE"
android:text="C" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="#+id/button0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#drawable/eins"
android:text="0" />
/LinearLayout>
/LinearLayout>
</HorizontalScrollView>
Thanks a lot for you help.
I fixed it making the layout completely new. Even that of course not the best way, it seemed faster than searching for errors
Ive got the problem that, when i click one of the buttons shown in xml below, the text on the button jumps down one line. So if the button is 1 line, no text is shown. If the button is 2 lines, only the first line is shown, in the buttom of the button.
Nothing in the onClick method changes the layout.
Heres the XML
<?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"
android:id="#+id/layout_main">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
.. a few other layouts and controls that works fine
<TableLayout
android:id="#+id/tableLayout276"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/TableRow10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/BtnRet"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Ret"
android:gravity="center"
android:textSize="18dp" />
<Button
android:id="#+id/BtnVisningsType"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Decimaltal"
android:gravity="center"
android:textSize="18dp" />
<Button
android:id="#+id/BtnFunktioner"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Funktioner"
android:gravity="center"
android:textSize="18dp" />
</TableRow>
</TableLayout>
.. a few other layouts and controls that works fine
</LinearLayout>
</ScrollView>
</LinearLayout>
Now, if i change the layout_width on the buttons to wrap_content, it all works fine (got the idea from When changing textview, the text on a button below the textview moves down. Help! ) - except the buttons now obviusly dont have the same width, and it looks messy.
Does anyone have any idea why this happens, and how i can both keep the text, and decide the size of the buttons?
This adds complexity to the layout but might be a solution.
Add a LinearLayout to your table row and use weights to control precise layout of your buttons. Something like this:
<TableRow
android:id="#+id/TableRow10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="3"
android:orientation="horizantal"/>
<Button
android:id="#+id/BtnRet"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Ret"
android:gravity="center"
android:textSize="18dp" />
<Button
android:id="#+id/BtnVisningsType"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Decimaltal"
android:gravity="center"
android:textSize="18dp" />
<Button
android:id="#+id/BtnFunktioner"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Funktioner"
android:gravity="center"
android:textSize="18dp" />
</LinearLayout>
</TableRow>
Caveats:
Might give a performance hit
Typed from memory, please excuse any typos
Not tested
use padding/margin to adjust precise sizing
A RelativeLayout might also work.
what is happening to me is pretty tricky...I have this xml file as a layout for the adapter of a list view object:
<?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:background="#color/exBackGround"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#color/exBackGround" >
<ImageView
android:id="#+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#color/exBackGround"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/lblFolderName"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/exBackGround"
android:gravity="center_vertical"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/exForeGround" />
<TextView
android:id="#+id/lblNumber"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/exBackGround"
android:gravity="center_vertical"
android:paddingRight="5dp"
android:text="100"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/exForeGround" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/exGradEnd" >
</FrameLayout>
</LinearLayout>
I can't understand why, this layout results in what it is expecetd to do, plus a black line at the top that I can't understand where it cames from. Unfortunately, as a new user, I can0t post the image, sorry.
Ok problem solved, I auto-answer my self in the case someone else will need it in the future. The black line seen in the graphical layout in eclipse was fake, just coming from my "type of display" selection on the top. The black line I was seeing in the final app, was the default divider for the ListView. To make it disappear, I have just set lv.setDividerHeight(0).
I want to put a scrollable EditText above a row of buttons such that the text component fills all the vertical space left free by the buttons. This is proving surprisingly difficult, not least because the ADT is buggy: it suggests that this layout will do and it does in Eclipse but not in the real application!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/view1"/>
<LinearLayout android:id="#id/view1"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<!-- buttons go here -->
</LinearLayout>
</RelativeLayout>
In this layout the text stretches to the full screen, as you might expect, i.e., it goes under the button but the ADT graphical layout tool shows it stopping just above the button. OTOH if you give it a wrap_content height then of course it doesn't stretch. layout_weight is of no help either.
So, is there a way? You must test your answer in the emulator or on a real device, not merely in Eclipse.
Precision: what makes me think this is not working and that the text widget extends under the buttons is the shape of the scrollbar at the bottom (see pic. below): it should be rounded at both ends and instead it looks like the bottom extends farther. If you compares its shape at the bottom with the shape it has at the top (which unfortunately I was unable to capture: it disappears too fast) it is very clearly different. OTOH the text widget boundary looks as expected. This is very confusing. Maybe just a minor bug in Android?
try this code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="textMultiLine" >
<requestFocus></requestFocus>
</EditText>
<LinearLayout
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:layout_width="match_parent">
<Button
android:text="Button"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="#+id/button1"
android:layout_width="0dp"></Button>
<Button
android:text="Button"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="#+id/button2"
android:layout_width="0dp"></Button>
<Button
android:text="Button"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="#+id/button3"
android:layout_width="0dp"></Button>
</LinearLayout>
</LinearLayout>
This should work
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="#+id/view1" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button android:text="Button" android:layout_weight="1"
android:layout_height="wrap_content" android:id="#+id/button1"
android:layout_width="0dp"/>
<Button android:text="Button" android:layout_weight="1"
android:layout_height="wrap_content" android:id="#+id/button2"
android:layout_width="0dp"/>
<Button android:text="Button" android:layout_weight="1"
android:layout_height="wrap_content" android:id="#+id/button3"
android:layout_width="0dp"/>
</LinearLayout>
<EditText android:id="#+id/text1" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_above="#id/view1"
android:gravity="top"/>
</RelativeLayout>
I did the same thing with TextView and a Button at the bottom.I tried to put EditText in place of TextView there and it works fine for me. You can try this -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/button"
android:text="Add New Template"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/editText"
android:layout_alignParentTop="true"
android:layout_above="#id/add_acronym"
/>
</RelativeLayout>
Here is the snapshot-
A custom Dialog box with a RelativeLayout contains a Button widget that won't change its margins, regardless of direction. Here's the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" android:background="#99000000">
<TextView android:id="#+id/dialogtitle" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Some text" />
<TextView android:id="#+id/dialogtext" android:layout_width="300dp"
android:layout_height="wrap_content" android:textSize="15dp"
android:layout_alignParentLeft="true" android:layout_below="#id/dialogtitle"
android:paddingLeft="8dp" />
<Button android:id="#+id/dialogbuttoninfo" android:layout_width="80dp"
android:layout_height="wrap_content" android:text="Doesn't care about margins"
android:layout_alignParentRight="true" android:layout_marginLeft="128dp" />
</RelativeLayout>
Padding works but only moves the text inside the button. Any suggestions?
This seems crappy but have you tried putting it all in a LinearLayout instead? or perhaps removing android:orientation="horizontal". I dont think RelativeLayout cares about orientation from what I've seen. Also I think, but might be wrong, that if you do a LinearLayout then you won't need to have android:layout_alignParentLeft="true" in there either.
After cleaning it up a bit (sorry but its so hard to read when its compressed as it was in the question) you also didn't state where the last TextView , dialogbuttoninfo was supposed to be relative to everything else, I think you have to do that for Relative layouts to behave properly, I've had some squirrely things happen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#99000000">
<TextView
android:id="#+id/dialogtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Some text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/dialogtext"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_alignParentLeft="true"
android:paddingLeft="8dp" />
<Button
android:id="#+id/dialogbuttoninfo"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="Doesn't care about margins"
android:layout_alignParentRight="true"
android:layout_marginLeft="128dp" />
</LinearLayout>
</LinearLayout>
You may need to align the left of the button against something before the margin has real meaning.