Android layout (TextView) - android

I'm new to android development and have some doubts with regards to layout design. I have the following codes but its not working as i wanted. I would like to have the image view display a photo i have taken and below it, a textbox for user to input data. However, at this moment, the image takes up the whole screen and I could not locate my textbox. Please kindly advice. Thanks!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="#+id/linear">
<ImageView android:id="#+id/imageView1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:contentDescription="#string/desc"/>
<EditText
android:id="#+id/editTextSimple1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<requestFocus />
</EditText>
</LinearLayout>

Use RelativeLayout instead of LinearLayout and USe below xml code instead of your xml code, it will solve your problem.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/editTextSimple1"
android:contentDescription="desc" />
<EditText
android:id="#+id/editTextSimple1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<requestFocus />
</EditText>
</RelativeLayout>

Change ImageView layout height to layout_height="wrap_content"
With layout_height="fill_parent", the image will take all the space.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="#+id/linear">
<ImageView android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"/>
<EditText
android:id="#+id/editTextSimple1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<requestFocus />
</EditText>
</LinearLayout>

The problem is
android:layout_height ="fill _parent"
This makes it occupy the whole parent space I.e. The whole screen
Either set the height to a specific value of dp,px etc. Or use
android:layout_height="wrap_content"
If view is small enough to fit on screen

<ImageView android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"/>
Add weight to your ImageView like this. It will work.

Related

Background fit LinearLayout

I want the background picture not to be deformed, but everytime I try, ImageView appears in front of other UI elements.
I already tried with an image view android:src and scaleType=center,
and when I try with another layout, then I can't make the picture fit.
try settings scaleType=matrix, if that didnt help either then there is issues with intrinsic padding , i will post customImageview Then.
cheers!
Try this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="#string/xxxx"
android:src="#drawable/xxxx" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/xxxx"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/today"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="xxx"
android:textSize="xxsp" />
</RelativeLayout>
</LinearLayout>

Android LinearLayout with Button and FrameLayout using the Maximum Height

I am trying to make a layout where there are a LinearLayout and inside it I want a FrameLayout and a button.
I want the button to use the bottom of the linearlayout and to use the maximum width and the enough height for the button, using wrap content.
The other component, the FrameLayout I want to use it the remaining part of the screen.
How can I do it?
Here it the layout so far..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="snapIt"
android:text="#string/Capture" />
</LinearLayout>
Is not showing the button :s
Thanks alot in advance ;)
Better to work out with relative layout with button aligned to parent bottom and your frame layout above it occupying the rest space of the screen.Like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_capture"/>
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
use the following xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"
android:text="capture" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_capture"
/>
</RelativeLayout>
i am just trying to make these layout, after compare my layout code and your layout code, i find a different code, there is in my code. Did you missing it or just move it away cause it useless from the layout code ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<FrameLayout
android:id="#id/flayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world">
</FrameLayout>
</LinearLayout>

How to make a edittext view fill the parent element in android

I have two edittext views. One of them has only one line, its the title. But the other one should fill the linearlayout to the end, but it doesn't.
I updated the code so this is my whole xml for this app. I hope someone can find what's wrong. The part that i want to form like this is the part inside the LinearLayout named addView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/addButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/addbuttonstyle"
android:layout_weight="20"/>
<ImageView
android:id="#+id/titleView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/titleview"
android:layout_weight="60"/>
<Button
android:id="#+id/orderButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/orderbuttonstyle"
android:layout_weight="20"/>
</LinearLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/addView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="#+id/textBoxTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="note title"
android:singleLine="true"
/>
<EditText
android:id="#+id/textBoxContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="content"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/backgroundLayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
/>
</FrameLayout>
I changed textBoxTitle's height to wrap_content and I see this:
Is this what you were hoping for? Also if you want content to appear in the upper-left corner use this attribute:
<EditText
...
android:gravity="top"
/>
So i found what was wrong.
I needed to set layout_height (of the textBoxContent view) to 0dp and layout_weight (of the textBoxContent view) to 1.
The first view should have android:layout_width="wrap_content"

Android Image above ListView?

I have a ListView whit two taps underneath it, but i cant seem to figure out how to put an Image above the ListView. I have tried just putting an ImageView on top, but it wont do it?
This is how it looks now.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<ImageView
android:id="#drawable/frederiksberg"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"/>
</LinearLayout>
Try this code and run
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/add" android:layout_gravity="center_horizontal"/>
<ListView
android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
It is working fine for me. Hope this helps you.
It is quite simple dude.
Take a Linear layout L1.
add one ImageView in L1 with Weight tag = 1
and add listview in L1 whose width and height must be fill parent.
make orientation of L1 as vertical..
let me know if any doubt.
here is solution make your parent layout as relative layout because it will provide you more flexiblity.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="122dp"
android:src="#drawable/ic_launcher" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1" >
</ListView>
</RelativeLayout>
hope it will work for you.. it is complete xml file i am posting for you try it.

Android: EditText next to ImageView - EditText as wide as possible

I'd like to have an EditText and an ImageView next to each other; the ImageView has a fixed width, the EditText should take the rest.
I try to do it via
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:id="#+id/edit_select_stop" android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:layout_gravity="center_vertical"
android:layout_width="39dp" android:minWidth="39dp"
android:layout_height="wrap_content" android:src="#drawable/icon_time"
android:id="#+id/image_select_time"></ImageView>
</LinearLayout>
</LinearLayout>
But now, the EditText takes the whole width and covers the Image.
How can I achieve that EditText "ends" before the ImageView?
You can also use RelativeLayout to accomplish it. Simply assign the properties
android:layout_toLeftOf="#+id/id_of_your_imageview"
android:layout_width="fill_parent"
to the EditText and
android:layout_alignParentRight="true"
to your ImageView while keeping the fixed value of the width.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditText
android:id="#+id/edit_select_stop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
</EditText>
<ImageView
android:id="#+id/image_select_time"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_weight="1"
>
</ImageView>
</LinearLayout>
Well I dont recommend to go for the relative layout..
for the code (2nd one) seems good but I'd like to add that you should set the gravity android:gravity="center_vertical"
This aligns the components and makes it look good for sure

Categories

Resources