View not showing properly in android layout - java

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>

Related

How to use scrollview over codeview?

i'm building an tutorial app where im displaying code snippet to user, but scrolling is just working on white area of the screen but not over the code snippet, may be codeview is overlapping the scrollview, How to resolve it so the codeview also scroll:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="activity_main.xml"
android:textColor="#android:color/black"
android:textStyle="bold"
android:layout_marginTop="5dp"
android:textSize="18sp"/>
<io.github.kbiakov.codeview.CodeView
android:id="#+id/code_view_xml"
android:layout_marginTop="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="create layout resource file inside layout directory with name:"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:textStyle="italic"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="single_item.xml"
android:textColor="#android:color/black"
android:textStyle="bold"
android:layout_marginTop="5dp"
android:textSize="18sp"/>
<io.github.kbiakov.codeview.CodeView
android:id="#+id/code_view_item"
android:layout_marginTop="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
here the output :
You are missing padding. Try adding padding.
Also your linearlayout height is match_parent. Change that to wrap and then try

ImageView covering other contents in android

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.

xml layout isn't working for me

I have a lot of info to put on one xml page. Now i got what I want in the positions i want. However instead of fitting all my data on 3 key parts without running into each other, It keeps running into the next TextView. I was wondering how to have it auto adjust.
<?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" >
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/back" />
<TextView
android:id="#+id/makeup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginTop="97dp"
android:text="#string/part_section_2" />
<TextView
android:id="#+id/part_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginLeft="19dp"
android:layout_marginTop="38dp"
android:text="put text here for info" />
<TextView
android:id="#+id/part_safety"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_makeup"
android:layout_below="#+id/safety_title"
android:layout_marginTop="28dp"
android:text="put text here for safety" />
<TextView
android:id="#+id/info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="42dp"
android:text="#string/part_section_1" />
<TextView
android:id="#+id/part_makeup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_info"
android:layout_below="#+id/makeup_title"
android:layout_marginTop="33dp"
android:text="put text here for makeup" />
<TextView
android:id="#+id/safety_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/part_makeup"
android:layout_marginTop="48dp"
android:text="#string/part_section_3" />
<TextView
android:id="#+id/part_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:textColor="#b70000"
android:textSize="16sp"
android:text="put text here for part title" />
</RelativeLayout>
would ScrollView work better? and how would switch this from this to ScrollView.
skin is 480x800
density is high(240)
Strings file - http://pastie.org/8534713
Changing to ScrollView (source):
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- your Button and TextView widgets -->
</RelativeLayout>
</ScrollView>
Edit:
As well as that, try changing your back button XML to this:
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/part_safety"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="#string/back" />
The problem was android:layout_alignParentBottom="true". The bottom ended up not going to the bottom of the page like you had before. The ScrollView cut back on the bottom of the layout.

MarginLeft doesn't work: Why?

i have this layout
<?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="wrap_content" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView2"
android:layout_marginLeft="13dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="16sp"
android:text="#string/text"
/>
</ScrollView>
</RelativeLayout>
I would like to know why on some phones or versions of Android (2.3 Gingerbread mainly) the margins are pratically 0, in the sense that it is not detached from the left margin but it is attached, as if there were no android:layout_marginLeft="13dp"
Try to add android:layout_gravity="left" to your textView. Value of layout_gravity can be any of valid list.
Try the following in your xml .I have added android:layout_gravity="left"
<TextView
android:id="#+id/textView2"
android:layout_marginLeft="13dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="16sp"
android:text="text"
/>

Layout Change Visibility

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);

Categories