I'm trying to develop an Augmented Reality aplication for Android using Metaio. But actually I've a problem.
I want to make a little menu appear when the aplication recongize a marker.
<?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="vertical" >
<ImageButton
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:onClick="onButtonClick"
android:contentDescription="#null"
android:src="#drawable/cancel" />
<LinearLayout
android:id="#+id/buttonBar123"
style="#android:style/ButtonBar"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:visibility="invisible"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="#+id/TextoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onTextoButtonClick"
android:text="Texto" />
<Button
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onImagemButtonClick"
android:text="Imagem" />
</LinearLayout>
</RelativeLayout>
My layout is on a View and I don't know how to change the ButtonBar123 to visible in Java code. Can you help me? Thanks
You just need to get a reference to your Layout
LinearLayout buttonBar = (LinearLayout) findViewById(R.id.buttonBar123);
then set the visibility
buttonBar.setVisibility(View.VISIBLE);
Visibility
LinearLayout buttonBar = (LinearLayout)findViewById(R.id.buttonBar123);
buttonBar.setVisibility(View.VISIBLE);
Related
The image is covering the textView and buttons(I cant even see them at all so I'm guessing they are behind the image). Image is attached. I want the textview and buttons to appear below the imageview. Below is my xml file.
<?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"
>
<ImageView
android:id="#+id/imageView9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:src="#drawable/bw" />
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2" />
</LinearLayout>
You can change the main layout to RelativeLayout, set the ImageView at the top and wrap the views below the ImageView, inside a separate layout.
By setting android:layout_above="#+id/linear" for the ImageView, you will be sure that the ImageView will never cover the other views.
<?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="vertical">
<ImageView
android:id="#+id/imageView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linear"
android:layout_alignParentTop="true"
android:scaleType="fitStart"
android:src="#drawable/bw" />
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:gravity="center_horizontal">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />
</LinearLayout>
</RelativeLayout>
Try changing the parent layout to a RelativeView, or a ConstraintView. If you don't want to redo your positioning of your layout, you can wrap everything except the Image in a LinearLayout.
<RelativeView>
<ImageView>
<LinearLayout>
//...All your stuff
</LinearLayout>
<RelativeView>
This isn't one way of course, try to experiment. Feel free to ask if you still encounter problems.
I want to design an android activity with a relative layout. There should be 3 (or later 4) elements in a vertical line among each other. I've tried it, but the textview is hidden behind the listview.
What's wrong with the code, how should I change it and how should it look, if I want to insert a fourth element between the text and listview or the listview and button ... like a image.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:paddingBottom="10dp"
android:layout_above="#+id/listview"
android:text="#string/info" />
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button"
android:layout_marginBottom="10dp" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="start"
android:src="#drawable/button1" />
</RelativeLayout>
Try changing ReltiveLayout to LinearLayoutor put LinearLayout outside your RelativeLayout, whith orientation="vertical" an put the TextView outside RelativeLayout. Something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/info" />
<RelativeLayout
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button"
android:layout_marginBottom="10dp" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="start"
android:src="#drawable/button1" />
</RelativeLayout>
</LinearLayout>
I am trying to display two texts in a layout such that they are displayed one after the other but the following code is pasting the strings right above each other. What should I do. I tried to exchange fill_parent & wrap_content between the two textviews but it is worthless
<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="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="false"
android:layout_centerVertical="false"
android:text="#string/hello_world"
tools:context=".StartingPoint" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="false"
android:layout_centerVertical="false"
android:text="#string/testing"
tools:context=".StartingPoint" />
You have to put the property below in the second TextView and set on the below property the id of the first TextView
change your two TextView by this two:
<TextView
android:id="#+id/TextView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="false"
android:layout_centerVertical="false"
android:text="#string/hello_world"
tools:context=".StartingPoint" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/TextView1"
android:layout_centerHorizontal="false"
android:layout_centerVertical="false"
android:text="#string/testing"
tools:context=".StartingPoint" />
But you need to read the documentation at android developers first, because that is very basic.
Hope to help :)
Use LinearLayout as the parent layout and set its orientation to horizontal. This will work.
You have to tell the RelativeLayout how it has to place the different views.
Documentation: http://developer.android.com/guide/topics/ui/layout/relative.html
It could be simpler to use a LinearLayout.
If you need RelativeLayout menas,
<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="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="FirstText"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="secondText"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Else you need LinearLayout means,
<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:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FirstText"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="secondText"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
In the Case of Relative layout you need the textview is one by one means use this parameter, android:layout_below="#+id/textView1" else you are using LinearLayout means use this parameter android:orientation="vertical"
In the UI for my application I have 5 ImageButton all is ok on the 3.7" screen but if I have a screen of 2.7", 3.0" or other my UI will not scale and it looks bad. It looks like this:
3,7"
2,7"
How do I make all have a nice look on all screens, just like on the screen 3.7"?
Code: main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/two"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:orientation="vertical"
android:scaleType="fitXY" >
<ImageButton
android:id="#+id/ibTest1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
</LinearLayout>
</RelativeLayout>
Use a RelativeLayout, and then place a LinearLayout with height wrap_content and put the buttons inside that LinearLayout. Also use dp instead of px for sizes.
P.S. If you post the code of your layout, we can help you better.
EDITED: Now that I can see your code I can show you want I meant with my answer:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/two"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:gravity="center"
android:layout_centerInParent="true" >
<ImageButton
android:id="#+id/ibTest1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
</LinearLayout>
</RelativeLayout>
Can you provide some code?
Maybe try add to in xml
android:scaleType="fitXY"
First make image for all
mdpi,hdpi,ldpi
as per their size.
take Lineatlayout in center for Buttons only.
then set property gravity="Center" ;
Make sure your are using dp insted of using 'px'..Its a common cause.
try this add in each imageview in xml
android:adjustViewBounds="true"
android:scaleType="centerCrop"
I am designing custom dialogue in android, For this purpose I designed xml file as
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#color/item_bg_color"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/custom_dialog_text"
android:textColor="#000000"
android:textSize="14dip"
android:typeface="serif"
android:singleLine="false"
android:text="You are not authorized to use this application."
android:layout_marginTop="10dip"/>
<Button android:id="#+id/custom_button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:layout_below="#+id/custom_dialog_text"
android:layout_toRightOf="#+id/custom_dialog_text"/>
</RelativeLayout>
Problem :
I want to show button at end (Right) of TextView, And textview's text should be in more than one line(if more characters have to show). But when I am using this layout, button is not appearing anywhere.
I used LinearLayout and TableLayout also and in both cases, button is appearing with a little part. Where am I wrong?
Basically you want to tell the button to be align to the right, take all the space it needs, then give the rest of the space to the TextView. You do this by specifying android:layout_layout_alignParentRight="true" for the button and android:layout_toLeftOf="#id/custom_button_ok" for the TextView. Mind the order!!!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#color/item_bg_color" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<Button android:id="#+id/custom_button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:layout_layout_alignParentRight="true" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/custom_dialog_text"
android:textColor="#000000"
android:textSize="14dip"
android:typeface="serif"
android:singleLine="false"
android:text="You are not authorized to use this application."
android:layout_marginTop="10dip"
android:layout_toLeftOf="#id/custom_button_ok"
/>
</RelativeLayout>
For Button add the attributes android:layout_alignParentRight,android:layout_below,they help you
try doin this..
<TextView android:layout_width="100dip"
android:layout_height="wrap_content"
android:id="#+id/custom_dialog_text"
android:textColor="#000000"
android:textSize="14dip"
android:typeface="serif"
android:singleLine="false"
android:text="You are not authorized to use this application."
android:layout_marginTop="10dip"/>
layout_belw and layout_rightof properties are set to same Id in text view.Just use layout_below.Also u can set gravity of button to bottom
Please try below code
<?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="wrap_content"
android:orientation="horizontal" android:weightSum="1.0">
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="0dp" android:layout_weight="0.85">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/custom_dialog_text"
android:textColor="#FFFFFF" android:textSize="14dip"
android:typeface="serif" android:singleLine="false"
android:text="You are not authorized to use zdsaddsad this application."
android:layout_marginTop="10dip" />
</RelativeLayout>
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="0dp" android:layout_weight="0.15">
<Button android:id="#+id/custom_button_ok"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Ok" />
</RelativeLayout>
</LinearLayout>