I am making an app where there is a custom search bar. I want there to be a search part that is big, a spinner for region selection that is a small square, and a search button that is also a small square.
Here is what I am talking about.
The code I have right now is this:
<LinearLayout 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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:hint="#string/summoner_name"
android:layout_width="wrap_content"
android:layout_weight="75"
android:layout_height="wrap_content"
android:id="#+id/summoner_name"/>
<Spinner
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/regions">
</Spinner>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/search_button"/>
</LinearLayout>
However, this makes the search half the screen, and the button for 2/5's the screen, and the spinner for a smaller ammount. Anyone know how to accomplish this?
Thanks :)
give weight 1 to EditText android:layout_weight="1" , and remove weight tags from other components.
Also you will require to set Spinners width statically, if above doesnt work because of Spinner's width part
like this?
<LinearLayout 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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:layout_width="wrap_content"
android:layout_weight="75"
android:layout_height="wrap_content"
android:id="#+id/summoner_name"/>
<Spinner
android:layout_weight="1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/regions"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/search_button"/>
</LinearLayout>
</LinearLayout>
Related
I want to show the word "STATS" above a Listview containing either 2 or 3 list items. I want the ListView at the bottom edge of the screen and the remaining space to be filled by the "STATS" TextView and the text centered vertically and horizontally. Basically a single word floating lonely in the exact middle of the remaining space.
I cannot do this in the "drag and drop" layout editor because it shows 8 placeholder items in the ListView, so I can't snap to the edges of things properly.
I've got the ListView how I want it, but the "STATS" is causing problems.
I've tried all sorts of things (apart from the right one, obviously). Here's my currently broken layout...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="uk.co.xxxxxxxxxxx.xxxxxxx.MainActivity"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom"
>
<TextView
android:id="#+id/tv_reboot_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textStyle="bold"
android:textAlignment="center"
android:text="#string/stats"
/>
<ListView
android:id="#+id/lv_app_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/reboot_screen_items"
android:layout_gravity="center_horizontal|center_vertical"
/>
</LinearLayout>
I'm sure it's something trivial to do but its driving me mad.
Try this, it works well
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv_reboot_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textStyle="bold"
android:textAlignment="center"
android:text="STATE"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center" />
<ListView
android:id="#+id/lv_app_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/reboot_screen_items"
android:layout_gravity="bottom" />
</LinearLayout>
Result
Can you try this?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="uk.co.xxxxxxxxxxx.xxxxxxx.MainActivity"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/tv_reboot_message"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30sp"
android:textStyle="bold"
android:textAlignment="center"
android:gravity="center"
android:text="STATS"
android:layout_above="#+id/lv_app_info"
/>
<ListView
android:id="#+id/lv_app_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/values"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
/>
</RelativeLayout>
You can use RelativeLayout to fill up the remaining space to show your TextView.
Use gravity and layout_gravity attributes.
Gravity and layout_gravity
I have a ScrollView which contains EditText, but the problem is it doesn't show properly in the emulator and on a physical device. Can anyone see any problems with my code?
XML snippet
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#drawable/background2"
tools:context="com.jack.cheng.buddhistcopy.Activity1">
<ScrollView
android:layout_width="300dp"
android:layout_height="300dp"
android:id="#+id/scrollView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:fillViewport="true"
android:isScrollContainer="true"
android:saveEnabled="true">
<TableLayout
android:id="#+id/sutra"
android:layout_width="295dp"
android:layout_height="295dp"
android:orientation="vertical"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:text="Test"
android:layout_width="10dp"
android:layout_height="10dp"
>
</EditText>
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
Did you try adding the following attribute to the ScrollView?
xmlns:android="http://schemas.android.com/apk/res/android"
Try using:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TestText"
/>
You might want to use the conditions : wrap_content, fill_parent or match_parent as using these allows your view elements to adjust accordingly to the device screen which can vary.
Also you might want to add an android:id="#id/myIdentifier" to that EditText so you can link it to whatever process you have going on in your app.
I've only ever seen questions asking how to full screen the VideoView but what I'm trying to do is have a video playing as only a part of the activity, with some additional elements on the page. How would I go about doing that? It doesn't seem that I have control of the size of the VideoView, I can only shift it around in the designer.
Edit: Additional Info
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.MyActivity">
<Button
Default button Stuff
/>
<TextView
Default textview stuff
/>
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/videoView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android: />
</RelativeLayout>
As far as ideal proportions go, maybe something like 500 x 400 dp? I can play with numbers after I understand the process.
If I understand you correctly, this is something that you'd want:
<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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.MyActivity">
<LinearLayout
android:id="#+id/componentLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<TextView
android:text="This is a placeholder text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<VideoView
android:layout_marginTop="20dp"
android:layout_below="#+id/componentLayout"
android:layout_width="300dp"
android:layout_height="400dp"
android:id="#+id/videoView"
android:layout_centerHorizontal="true" />
</RelativeLayout>
You can define the android:layout_width and android:layout_height attributes as you wish. However, they can not exceed the height or width of the parent layout.
Result:
Width: 300dp, Height: 400dp
I work with android, I want to draw design like this
There are two LinearLayuots ( blue and white ), I want add picture their borders, I have tryied to use minus margin but not work
Can Anybody help me?
You'd want something like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/firstRow"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#013032"
android:orientation="horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#ff3e7730"
android:layout_below="#+id/firstRow"/>
<ImageView
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:layout_width="140dp"
android:layout_height="140dp"/>
</RelativeLayout>
you can use a RelativeLayout for your layout's parent and then add two LinearLayout and one ImageView or Button. and set your Button (or ImageView,etc) to centerVertical and alignParentLeft and give some marginLeft to it!
<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="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.neo.myapplication.MyActivity">
<LinearLayout
android:id="#+id/aboveLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/darker_gray"
></LinearLayout>
<LinearLayout
android:layout_below="#+id/aboveLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/holo_green_dark"></LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/ic_launcher"/>
</RelativeLayout>
I'm trying to put a TextView on top, another on bottom, and a ListView in between using the remaining space.
However, my ListView is taking all the space to the bottom, making the last TextView to not even show up. The only way I can make it show up is to give the ListView a fixed height, like 100dp.
My layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/id_task_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_task_list"
style="?android:attr/listSeparatorTextViewStyle" />
<ListView
android:id="#+id/id_task_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/id_task_list_title" />
<TextView
android:id="#+id/id_task_list_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/id_task_list_view"
android:text="OMG Test" />
</RelativeLayout>
Use LinearLayout as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="#+id/id_task_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_task_list"
style="?android:attr/listSeparatorTextViewStyle" />
<ListView
android:id="#+id/id_task_list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<TextView
android:id="#+id/id_task_list_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OMG Test" />
</LinearLayout>
This should solve your issue by placing your ListView between the TextViews using both android:layout_above and android:layout_below :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/id_task_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_task_list"
style="?android:attr/listSeparatorTextViewStyle" />
<TextView
android:id="#+id/id_task_list_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="OMG Test" />
<ListView
android:id="#+id/id_task_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/id_task_list_test"
android:layout_below="#id/id_task_list_title"/>
</RelativeLayout>
It can be achieved one of the two ways
1) Using Linear Layout (Straight forward)
2) Using Relative Layout with referencing the view position with respected to the other views.
In your case
1) Change Relative to LinearLayout and work will be done.
2)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/id_task_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_task_list"
style="?android:attr/listSeparatorTextViewStyle" />
<ListView
android:layout_below="#+id/id_task_list_title"
android:id="#+id/id_task_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/id_task_list_title" />
<TextView
android:layout_below="#+id/id_task_list_view"
android:id="#+id/id_task_list_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/id_task_list_view"
android:text="OMG Test" />
</RelativeLayout>
This can be done through coding by getting the height of screen and alloting layout param width to list view like this
height of list view=screen height-(height of textView1+Height of textView2).
Instead of Using RelativeLayout , use LinearLayout with Orientation Vertical.
I think it solves your problem
Thank you