Two Relative Layouts on the one screen - android

i want to have 2 Relative Layouts on my screen. One below another. I made this code but it doesn't work. In this case i can see only upper Relative Layout insted of both and this layout take whole space although i set wrap_content.
EDIT!: I put below the second code which fails too.
EDIT 2!: I found problem... That's a bit... sad. Problem lie in my theme. I set background to png file which was too big and when i applied default theme via manifest then this happend. When i removed it all is good.
This version fails too.
New code:
<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" >
<RelativeLayout
android:id="#+id/some_id"
android:layout_above="#+id/some_id2"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/main_button_localize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/main_localize" />
</RelativeLayout>
<RelativeLayout
android:id="#id/some_id2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ToggleButton
android:id="#+id/main_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
Old code:
<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" >
<RelativeLayout
android:id="#+id/maps_manager_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<!-- Top -->
<Button
android:id="#+id/maps_manager_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_top_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_top_left"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_top_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_top_middle"
android:contentDescription="#string/empty" />
<!-- Middle -->
<Button
android:id="#+id/maps_manager_middle_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/maps_manager_top_left"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_middle_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_middle_left"
android:layout_below="#id/maps_manager_top_middle"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_middle_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_middle_middle"
android:layout_below="#id/maps_manager_top_right"
android:contentDescription="#string/empty" />
<!-- Bottom -->
<Button
android:id="#+id/maps_manager_bottom_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/maps_manager_middle_left"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_bottom_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_bottom_left"
android:layout_below="#id/maps_manager_middle_middle"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_bottom_middle"
android:layout_below="#id/maps_manager_middle_right"
android:contentDescription="#string/empty" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/maps_manager_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="true"
android:layout_below="#id/maps_manager_menu" >
<ToggleButton
android:id="#+id/maps_manager_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>

Better you take LinearLayout with vertical orientation as Parent for two child RelativeLayouts. If you can put 80:20 height weights for the RelativeLayouts then it would fit to the entire screen.

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<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" >
<RelativeLayout
android:id="#+id/maps_manager_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<!-- Top -->
<Button
android:id="#+id/maps_manager_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_top_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_top_left"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_top_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_top_middle"
android:contentDescription="#string/empty" />
<!-- Middle -->
<Button
android:id="#+id/maps_manager_middle_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/maps_manager_top_left"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_middle_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_middle_left"
android:layout_below="#id/maps_manager_top_middle"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_middle_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_middle_middle"
android:layout_below="#id/maps_manager_top_right"
android:contentDescription="#string/empty" />
<!-- Bottom -->
<Button
android:id="#+id/maps_manager_bottom_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/maps_manager_middle_left"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_bottom_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_bottom_left"
android:layout_below="#id/maps_manager_middle_middle"
android:contentDescription="#string/empty" />
<Button
android:id="#+id/maps_manager_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_bottom_middle"
android:layout_below="#id/maps_manager_middle_right"
android:contentDescription="#string/empty" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/maps_manager_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="true"
android:layout_below="#id/maps_manager_menu" >
<ToggleButton
android:id="#+id/maps_manager_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>

<ScrollView 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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/maps_manager_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<!-- Top -->
<Button
android:id="#+id/maps_manager_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/hello_world" />
<Button
android:id="#+id/maps_manager_top_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_top_left"
android:contentDescription="#string/hello_world" />
<Button
android:id="#+id/maps_manager_top_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_top_middle"
android:contentDescription="#string/hello_world" />
<!-- Middle -->
<Button
android:id="#+id/maps_manager_middle_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/maps_manager_top_left"
android:contentDescription="#string/hello_world" />
<Button
android:id="#+id/maps_manager_middle_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_middle_left"
android:layout_below="#id/maps_manager_top_middle"
android:contentDescription="#string/hello_world" />
<Button
android:id="#+id/maps_manager_middle_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_middle_middle"
android:layout_below="#id/maps_manager_top_right"
android:contentDescription="#string/hello_world" />
<!-- Bottom -->
<Button
android:id="#+id/maps_manager_bottom_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/maps_manager_middle_left"
android:contentDescription="#string/hello_world" />
<Button
android:id="#+id/maps_manager_bottom_middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_bottom_left"
android:layout_below="#id/maps_manager_middle_middle"
android:contentDescription="#string/hello_world" />
<Button
android:id="#+id/maps_manager_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/maps_manager_bottom_middle"
android:layout_below="#id/maps_manager_middle_right"
android:contentDescription="#string/hello_world" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/maps_manager_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/maps_manager_menu" >
<ToggleButton
android:id="#+id/maps_manager_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>

Follow the following steps:
Add ID to topmost relative layout say: android:id="#+id/rtvlt_first"
In second RelativeLayout remove alignparenttop property.
Add android:tobottomof="#id/rtvlt_first"...
Try this....
Good Luck!

Related

Android Studio aligning elements to other elements under them

Hello I'm using android studio for mobile app development and I need to make 3 LinearLayouts the same size. The problem is that the first element contains different element. I need to stretch first element to have exactly the same size as others. I guess I can somehow get to know that is the size of elements and set the value to the first element. Maybe there is a possibility to align them somehow? That is how it looks. Thanks for help!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:gravity="center_horizontal"
tools:context=".MainView.MainActivity"
android:orientation="vertical"
android:paddingTop="100dp">
<!-- rounds View -->
<TextView
style="#style/option_type_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rounds" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="#+id/minus_round_button"
style="#style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minus" />
<EditText
android:id="#+id/round_minutes"
style="#style/option_input_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/default_time" />
<Button
android:id="#+id/plus_round_button"
style="#style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/plus"/>
</LinearLayout>
<!-- end rounds View-->
<!-- work View -->
<TextView
style="#style/option_type_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/work" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="#+id/minus_work_button"
style="#style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minus" />
<EditText
android:id="#+id/work_minutes"
style="#style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/default_time" />
<TextView
style="#style/option_input_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"/>
<EditText
android:id="#+id/work_seconds"
style="#style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/default_time" />
<Button
android:id="#+id/plus_work_button"
style="#style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/plus"/>
</LinearLayout>
<!-- end Work View-->
<!-- rest View -->
<TextView
style="#style/option_type_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rest" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="#+id/minus_rest_button"
style="#style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minus" />
<EditText
android:id="#+id/rest_minutes"
style="#style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/default_time" />
<TextView
style="#style/option_input_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"/>
<EditText
android:id="#+id/rest_seconds"
style="#style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/default_time" />
<Button
android:id="#+id/plus_rest_button"
style="#style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/plus"/>
</LinearLayout>
<!-- end Rest View-->
</LinearLayout>
Make your first element as follows:
<TextView
style="#style/option_type_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rounds" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="#+id/minus_round_button"
style="#style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minus" />
<EditText
android:id="#+id/round_minutes"
style="#style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/default_time" />
<Button
android:id="#+id/plus_round_button"
style="#style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/plus"/>
</LinearLayout>

Centering a TextView while keeping it to the left of a button?

Requirement
I've got a button and a textview, and I want the textview to be centered in the parent view, while the button is on the right side in the parent view.
Approach
So I took a RelativeLayout, make the textview layout_centerHorizontal="true", and the button layout_alignParentRight="true".
Code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/title_header_TV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="TextView" />
<!-- Doesnt work -->
<!-- android:layout_toLeftOf="#+id/right_button" -->
<Button
android:id="#+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
Problem
So when the text is too long, it gets written on top of the button.
I tried doing layout_toLeftOf="#+id/right_button" on the textview, but now TextView is no longer centered.
Try this.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:id="#+id/title_header_TV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="TextView" />
<Button
android:id="#+id/right_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</TableRow>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Doesnt work -->
<!-- android:layout_toLeftOf="#+id/right_button" -->
<Button
android:id="#+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
<TextView
android:id="#+id/title_header_TV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/right_button"
android:layout_alignBottom="#+id/right_button"
android:layout_alignParentLeft="true"
android:layout_marginLeft="80dp"
android:text="TextView" />
try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/title_header_TV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/right_button"
android:gravity="center"
android:text="This is a test message, This is a test message This is a test message " />
<!-- Doesnt work -->
<!-- android:layout_toLeftOf="#+id/right_button" -->
<Button
android:id="#+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/title_header_TV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toLeftOf="#+id/right_button"
android:gravity="center"
android:text="TextView " />
<Button
android:id="#+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
check this out. a very simple solution for you
Please change to
`
<Button
android:id="#+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
<TextView
android:id="#+id/title_header_TV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/right_button"
android:layout_alignTop="#id/right_button"
android:layout_centerHorizontal="true"
android:layout_toLeftOf="#id/right_button"
android:gravity="center"
android:text="TextView" />
`
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Doesnt work -->
<!-- android:layout_toLeftOf="#+id/right_button" -->
<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_marginLeft="15dp"
android:layout_marginTop="17dp"
android:gravity="center"
android:text="Add your demo text here for small and large"
android:layout_toLeftOf="#+id/button1"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView1"
android:layout_marginLeft="19dp"
android:text="Button"
android:layout_alignParentRight="true"/>
</RelativeLayout>

Can't add scrollView to layout

I have to split my layout in two parts:
the upper part shall be without ScrollView (in order to draw horizontal and vertical lines. I have got problems to draw vertical Lines, when the complete Layout have got a ScrollView)
the lower part shall be with ScrollView (in order to scroll through different Elements)
This picture shall explain, how it should look like:
My layoutfile looks like that:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawingLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical" >
<com.unitnode.Drawing
android:id="#+id/drawingView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="#+id/eraseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rubber" />
<ImageButton
android:id="#+id/undoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/undo" />
<ImageButton
android:id="#+id/neuerZeichenButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/newbutton" />
<ImageButton
android:id="#+id/saveZeichenView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/savebutton" />
<View
android:id="#+id/linie1"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />
<TextView
android:id="#+id/hintergrundfarbeFullZeichenView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hintergrundfarbe" />
<Button
android:id="#+id/hintergrundfarbeFullButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/schwarzbuttonshape" />
<Button
android:id="#+id/hintergrundfarbeFullButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/roterbuttonshape" />
<Button
android:id="#+id/hintergrundfarbeFullButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/gelberbuttonshape" />
<Button
android:id="#+id/hintergrundfarbeFullButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/weiserbuttonshape" />
<ImageButton
android:id="#+id/hintergrundfarbeFullButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/farbpallete" />
<View
android:id="#+id/linie2"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />
<TextView
android:id="#+id/strichfarbeFullText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Strichfarbe" />
<Button
android:id="#+id/strichfarbeFullButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/schwarzbuttonshape" />
<Button
android:id="#+id/strichfarbeFullButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/roterbuttonshape" />
<Button
android:id="#+id/strichfarbeFullButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/gelberbuttonshape" />
<Button
android:id="#+id/strichfarbeFullButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/weiserbuttonshape" />
<ImageButton
android:id="#+id/strichfarbeFullButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/farbpallete" />
<View
android:id="#+id/linie3"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />
<TextView
android:id="#+id/strichdickeTextFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Strichdicke" />
<SeekBar
android:id="#+id/strokeSeekbarFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/strichdickeTextMinFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0dp" />
<View
android:id="#+id/linie4"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />
<TextView
android:id="#+id/opacityText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Durchsichtigkeit: " />
<TextView
android:id="#+id/opacityMinText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0% " />
<SeekBar
android:id="#+id/opacitySeekbarFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="#+id/unschaerfeFilterCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unschärfefilter AN/AUS"
android:textSize="12sp" />
<TextView
android:id="#+id/radiusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radius:" />
<TextView
android:id="#+id/radiusMinTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1dp" />
<SeekBar
android:id="#+id/unschaerfeSeekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/unschaerfeCheckBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inner"
android:textSize="10sp" />
<RadioButton
android:id="#+id/unschaerfeCheckBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:textSize="10sp" />
<RadioButton
android:id="#+id/unschaerfeCheckBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Outer"
android:textSize="10sp" />
<RadioButton
android:id="#+id/unschaerfeCheckBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solid"
android:textSize="10sp" />
<TextView
android:id="#+id/formenText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Formen: " />
<ImageButton
android:id="#+id/kreisFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/kreis" />
the Element com.unitnode.Drawing is my Drawing View (the upper part).
I tried different things without success:
defined 1 ScrollView over whole page and tried to limit the height of it -> vertical lines can't be drawn
changed layout_height to wrap_content -> no change. I defined it to com.unitnode.Drawing too, but the app shut down because of onSizeChanged( ) method (width and height must > 0)
I tried to insert a ScrollView element after the drawing View. And added for this another Framelayout -> can't handle that
If you need Java code, please let me know.
Please help me to change my code, so that the layout consists of two part (shown in picture)
EDIT: I changed my xml file to this (used FrameLayout because of correct formatting):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawingLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/drawingLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.unitnode.Drawing
android:id="#+id/drawingView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/eraseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rubber" />
<ImageButton
android:id="#+id/undoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/undo" />
<ImageButton
android:id="#+id/neuerZeichenButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/newbutton" />
<ImageButton
android:id="#+id/saveZeichenView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/savebutton" />
<View
android:id="#+id/linie1"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />
<TextView
android:id="#+id/hintergrundfarbeFullZeichenView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hintergrundfarbe" />
<Button
android:id="#+id/hintergrundfarbeFullButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/schwarzbuttonshape" />
<Button
android:id="#+id/hintergrundfarbeFullButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/roterbuttonshape" />
<Button
android:id="#+id/hintergrundfarbeFullButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/gelberbuttonshape" />
<Button
android:id="#+id/hintergrundfarbeFullButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/weiserbuttonshape" />
<ImageButton
android:id="#+id/hintergrundfarbeFullButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/farbpallete" />
<View
android:id="#+id/linie2"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />
<TextView
android:id="#+id/strichfarbeFullText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Strichfarbe" />
<Button
android:id="#+id/strichfarbeFullButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/schwarzbuttonshape" />
<Button
android:id="#+id/strichfarbeFullButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/roterbuttonshape" />
<Button
android:id="#+id/strichfarbeFullButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/gelberbuttonshape" />
<Button
android:id="#+id/strichfarbeFullButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/weiserbuttonshape" />
<ImageButton
android:id="#+id/strichfarbeFullButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/farbpallete" />
<View
android:id="#+id/linie3"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />
<TextView
android:id="#+id/strichdickeTextFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Strichdicke" />
<SeekBar
android:id="#+id/strokeSeekbarFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/strichdickeTextMinFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0dp" />
<View
android:id="#+id/linie4"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />
<TextView
android:id="#+id/opacityText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Durchsichtigkeit: " />
<TextView
android:id="#+id/opacityMinText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0% " />
<SeekBar
android:id="#+id/opacitySeekbarFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="#+id/unschaerfeFilterCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unschärfefilter AN/AUS"
android:textSize="12sp" />
<TextView
android:id="#+id/radiusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radius:" />
<TextView
android:id="#+id/radiusMinTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1dp" />
<SeekBar
android:id="#+id/unschaerfeSeekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/unschaerfeCheckBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inner"
android:textSize="10sp" />
<RadioButton
android:id="#+id/unschaerfeCheckBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:textSize="10sp" />
<RadioButton
android:id="#+id/unschaerfeCheckBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Outer"
android:textSize="10sp" />
<RadioButton
android:id="#+id/unschaerfeCheckBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solid"
android:textSize="10sp" />
<TextView
android:id="#+id/formenText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Formen: " />
<ImageButton
android:id="#+id/kreisFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/kreis" />
</FrameLayout>
</ScrollView>
</FrameLayout>
You should try your layout as below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawingLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/drawingContainerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Need to add your drawing view-->
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<!-- Bottom views that are scrollable -->
</LinearLayout>
</ScrollView>
</LinearLayout>
It seems, that the ScrollView is located on Top of the whole underlaying FrameLayout. That's the reason, because I can't draw anything. When I set the Visibilty of the ScrollView to invisible than I am able to draw again. But I can't see the elements anymore certainly.
Is there an other way than changing the visibility? Is it possible to bring the underlaying FrameLayout to the front and how could I achieve that?

put button in one line with same space between all button

i want to put five button in bottom but all button should be with same space means
below is image
Here you can see that second and third image is not in center below is my code i know that i have put padding but still my problem is not solving, i have tried using linearlayout also in that i have done by using weight=1 and width =0 but button is stretching
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/wall"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:drawingCacheQuality="high"
android:scaleType="fitXY" />
<Button
android:id="#+id/butRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#drawable/check_right" />
<Button
android:id="#+id/butfav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/fvrt1" />
<Button
android:id="#+id/butLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:background="#drawable/check_left" />
<Button
android:id="#+id/butSetWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="39dp"
android:layout_toRightOf="#+id/butLeft"
android:background="#drawable/chek_wallpaper" />
<Button
android:id="#+id/butSetRingTone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginRight="36dp"
android:layout_toLeftOf="#+id/butRight"
android:background="#drawable/check_ringtone" />
can anybody help me?
I always use LinearLayout to achieve this and instead Buttons I'm using ImageView.
I have tried below code it's worked for me try this, just replace with your RelativeLayout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true" >
<ImageView
android:id="#+id/butLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/check_left" />
<View
android:id="#+id/butOne"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/check_right" />
<ImageView
android:id="#+id/butSetWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/chek_wallpaper" />
<View
android:id="#+id/butTwo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/check_right" />
<ImageView
android:id="#+id/butfav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/fvrt1" />
<View
android:id="#+id/butThree"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/check_right" />
<ImageView
android:id="#+id/butSetRingTone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/check_ringtone" />
<View
android:id="#+id/butFour"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/check_right" />
<ImageView
android:id="#+id/butRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/check_right" />
</LinearLayout>
out put will be generated as you wish
Its a bit dirty solution but It'll work :
<?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="horizontal" >
<LinearLayout
android:id="#+id/aaaa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/butRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:minWidth="48dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/bbbb"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/butfav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:minWidth="48dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/cccc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:minWidth="48dp"
android:orientation="vertical" >
<Button
android:id="#+id/butLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:minWidth="48dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ddd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/butSetWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:minWidth="48dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/gggg"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/butSetRingTone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:minWidth="48dp" />
</LinearLayout>
</LinearLayout>
Wrap the buttons in a LinearLayout and put spacings between each button (i also added one at the beginning and one after the last one, remove them if you don't want it).
assign a layout_weight for each spacing, don't set a weightSum on the LinearLayout.
Enjoy.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/wall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawingCacheQuality="high"
android:scaleType="fitXY" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<!-- this is for the spacing -->
<View
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/butRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/check_right" />
<!-- this is for the spacing -->
<View
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/butfav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/fvrt1" />
<!-- this is for the spacing -->
<View
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/butLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/check_left" />
<!-- this is for the spacing -->
<View
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/butSetWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/chek_wallpaper" />
<!-- this is for the spacing -->
<View
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/butSetRingTone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/check_ringtone" />
<!-- this is for the spacing -->
<View
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</FrameLayout>
Why all of you doing trick with code. In android coding there is option available to give space between item.
<Space
android:id="#+id/space1"
android:layout_below="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="40dp"
/>
Just use this whenever you want. simple. hope this will help you.

How to center two views within a relative layout?

The task is simple: there are two buttons and a TextView above them. All the widgets shoud be centered within the relative layout. The only one idea I have is create the third widget View and use it as a center axis for the buttons. Any ideas? A redundant layout isn't a good solution.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tv_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/app_name" />
<View
android:id="#+id/view_axis"
android:layout_width="1dp"
android:layout_height="1dp"
android:layout_below="#id/tv_progress"
android:layout_centerInParent="true" />
<Button
android:id="#+id/button_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_progress"
android:layout_toLeftOf="#id/view_axis"
android:text="#string/start" />
<Button
android:id="#+id/button_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_progress"
android:layout_toRightOf="#id/view_axis"
android:text="#string/stop" />
</RelativeLayout>
If I understand what you want correctly, you can put the Buttons in a LinearLayout and center that
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tv_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/app_name" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/tv_progress">
<Button
android:id="#+id/button_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start" />
<Button
android:id="#+id/button_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/stop" />
</LinearLayout>
I'm not sure if that's what you meant by a "redundant layout" but doing this is fine if it gives you what you want.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="#+id/sp_rooms"
android:layout_toLeftOf="#id/space"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Space
android:id="#+id/space"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn_registration"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/space"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
This will vertically and horizontally center the whole block consisting of the textview + buttons
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true">
<TextView
android:id="#+id/tv_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start" />
<Button
android:id="#+id/button_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/stop" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Categories

Resources