setVisibility hides nearby objects aswell - android

Im hiding a button from within a handler (This is after i have made it Visible in another state of the app). The handler receives a message from a running thread and then updates the GUI.
The problem is that nearby (not all) buttons and textviews are also dissappearing from the screen.. Im using Relative Layout.
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget54"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/btnFold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Fold"
android:visibility="invisible"/ >
<Button
android:id="#+id/btnRaise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/btnFold"
android:text="Raise"
android:visibility="invisible"/>
<Button
android:id="#+id/btnCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/btnRaise"
android:text="Call"
android:visibility="invisible" />
<TextView
android:id="#+id/txtFlopTurnRiver"
android:layout_width="135dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=" " />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnCall"
android:layout_toLeftOf="#+id/btnCall"
android:text="Chip amount:" />
<TextView
android:id="#+id/txtHand1"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:layout_above="#+id/textView1"
android:layout_centerHorizontal="true"
android:text=" " />
<Button
android:id="#+id/btnDeal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="#string/deal_deck"
android:visibility="invisible" />
<Button
android:id="#+id/btnRiver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/btnDeal"
android:text="River"
android:visibility="invisible" />
<TextView
android:id="#+id/txtHand2"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:layout_above="#+id/txtHand1"
android:layout_toLeftOf="#+id/btnRaise"
android:text=" " />
<TextView
android:id="#+id/txtHand3"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/btnRaise"
android:layout_centerVertical="true"
android:text=" " />
<TextView
android:id="#+id/txtHand8"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:layout_above="#+id/txtHand1"
android:layout_alignLeft="#+id/btnRiver"
android:text=" " />
<TextView
android:id="#+id/txtHand6"
android:layout_width="73dp"
android:layout_height="21dp"
android:layout_above="#+id/txtFlopTurnRiver"
android:layout_alignLeft="#+id/txtHand8"
android:layout_marginBottom="26dp"
android:text=" " />
<TextView
android:id="#+id/txtHand4"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txtHand6"
android:layout_alignBottom="#+id/txtHand6"
android:layout_toLeftOf="#+id/btnRaise"
android:text=" " />
<TextView
android:id="#+id/txtHand5"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:layout_above="#+id/txtHand4"
android:layout_alignLeft="#+id/txtHand1"
android:layout_marginBottom="14dp"
android:text=" " />
<TextView
android:id="#+id/txtHand7"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txtHand3"
android:layout_alignBottom="#+id/txtHand3"
android:layout_alignRight="#+id/btnRiver"
android:layout_marginRight="26dp"
android:text=" " />
<TextView
android:id="#+id/txtChipAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_toLeftOf="#+id/btnCall"
android:layout_toRightOf="#+id/txtHand1"
android:text="103360" />
Does anyone know what could be causing the problem?
btnFold = (Button)findViewById(R.id.btnFold);
btnFold.setVisibility(View.GONE);

Now that I see your full xml - when you set a View to GONE, views that are set relative to it (layout_toLeftOf, layout_above) are put in the top left (or wherever their other constraints put them, e.g. a view that is toLeftOf and aligned parent bottom will go to the bottom left of screen now (it has nothing to be toLeftOf and is on bottom). I'd recommend setting View.INVISIBLE if you just want to hide a View, not View.GONE unless you have a specific reason for that?

Just wrap the button you want to hide with a
<LinearLayout
android:id="#+id/LLid"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
....
>
</LinearLayout>
And made all layout_toLeftOf to the LinearLayout(LLid)
After that you define a visibility:gone to your button, and show them with setVisibility(VIEW.VISIBLE)

Related

Android TextView not shown

I have debugged and everything goes fine; moreover, in Graphical Layout everything is fine. here you can see the code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:background="#color/white" >
<ImageView
android:id="#+id/image"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginStart="5dp"
android:src="#drawable/news_img1" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#id/image"
android:text="Pizza Rondon"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_toEndOf="#id/image"
android:text="Ingredients: meat, potato, tomato, salad included too. " />
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginEnd="20dp"
android:text="60 Lei"
android:textColor="#color/dimmed_red"
android:textStyle="bold" />
</RelativeLayout>
and here is the result as this view is an item from ExpandableListView:
I dont set any data to TextViews inside my customAdapter. What could cause the TextViews to dissapear? I can't even see any difference between price and others two which are not shown, which do not differ much in layout.
Did you try changing text color - maybe it is set to white??? The price is showing because android:textColor="#color/dimmed_red"

Introducing marginTop in RelativeLayout creates overlapping

I'm trying to display information to the user through the use of a RelativeLayout but when I use layout_marginTop or paddingTop to create some spacing betweem my items the item below won't take in into account and they will both start overlapping.
Here are a few pics to help understand my problem :
Initial situation:
Adding a android:marginTop="48dip" to the TextView to better illustrate the problem:
I also tried adding the same android:marginTop="48dip" to the EditText but the result was unexpected too. (Link to the screenshot can be find in the comment as a user with less than 10 reputation can't post more than 2 links)
The Layout I'm using (simplified version)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp">
<!--Identification part-->
<TextView
android:id="#+id/idPartTV"
android:text="Site"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<View
android:id="#+id/idPartLine"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="#id/idPartTV"
android:layout_marginTop="4dip"
android:background="#android:color/darker_gray" />
<!--Site name-->
<TextView
android:id="#+id/siteNameTV"
android:text="Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/idPartLine"
android:layout_marginTop="8dip" />
<EditText
android:id="#+id/siteName"
local:MvxBind="Text Name"
android:layout_below="#id/idPartLine"
android:layout_toRightOf="#+id/transTV"
android:layout_alignBaseline="#id/siteNameTV"
android:layout_width="wrap_content"
android:layout_height="48dip" />
<!--Site ID-->
<TextView
android:id="#+id/siteIdTV"
android:text="ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/siteName" />
<EditText
android:id="#+id/siteID"
local:MvxBind="Text Id"
android:layout_width="wrap_content"
android:layout_height="48dip"
android:layout_below="#id/siteName"
android:layout_toRightOf="#id/transTV"
android:layout_alignBaseline="#id/siteIdTV" />
<!--location Part-->
<TextView
android:id="#+id/locPartTV"
android:text="Location"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/siteID" />
<View
android:id="#+id/locPartLine"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="#id/locPartTV"
android:background="#android:color/darker_gray"
android:layout_marginTop="4dip" />
<!--Latitude-->
<TextView
android:id="#+id/latTV"
android:text="Latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/locPartLine" />
<EditText
android:id="#+id/latitude"
local:MvxBind="Text Latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/locPartLine"
android:layout_toRightOf="#id/transTV"
android:layout_alignBaseline="#id/latTV"
android:inputType="numberDecimal" />
<!--Longitude-->
<TextView
android:id="#+id/longTV"
android:text="Longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/latitude" />
<EditText
android:id="#+id/longitude"
local:MvxBind="Text Longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/latitude"
android:layout_toRightOf="#id/transTV"
android:layout_alignBaseline="#id/longTV"
android:inputType="numberDecimal" />
</RelativeLayout>
</ScrollView>
In the snippet of code above, transTV is my largest TextView. I'm using it to be sure that all the EditText will be vertically aligned. SiteID is another EditText that is situated above the one presented here. As I had a lot of them I mutilated my code to avoid redundancies.
In my idea of the android:marginTop and of the RelativeLayout, adding some space between the latitude and the separating line should be taken into account to calculate the position of the longitude as it is set to be below the latitude using android:layout_below.

Android Text View - Top and Bottom edges clipped off

Somebody can please explain this?
Why the third TextView is weird?
The definitions for the 2 lines before are the same, and I haven't touched the style with java...
Edit: I've added the XML Layout file.
The XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top" >
<TextView
android:id="#+id/quadEqu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="#string/quadequ"
android:textSize="27sp" />
<Button
android:id="#+id/closeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:text="#string/close"
android:onClick="close" />
<TextView
android:id="#+id/stepOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/quadEqu"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="#string/quadEquForm"
android:textSize="18sp" />
<TextView
android:id="#+id/stepTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/stepOne"
android:layout_below="#+id/stepOne"
android:text="#string/quadEquForm"
android:textSize="18sp" />
<TextView
android:id="#+id/stepThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/stepOne"
android:layout_below="#+id/stepTwo"
android:text="#string/quadEquForm"
android:textSize="18sp" />
</RelativeLayout>
It's a strange behaviour.
Try to set the content of the 'stepTwo' to the 'stepThree'.
If the same issue appeared, so the problem from the TextView.
You should check if you modify the padding of 'stepThree' textView programmatically.
In android Text View, when you try to render the subscript, the text gets clipped at the top and bottom. To avoid this, you can try to set the text from HTML.
Example.
stepThree.setText(Html.fromHtml("Some text<sup><small>1</small></sup>"));
stepThree.setText(Html.fromHtml(
"HCO<sub><small><small>3</small></small></sub>));
Refer this link for more details.
Android TextView's subscript being clipped off
Subscript and Superscript a String in Android
You need to change android:layout_height for the TextView (for all 3 is better).
<TextView
android:id="#+id/stepOne"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#+id/quadEqu"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="#string/quadEquForm"
android:textSize="18sp" />
<TextView
android:id="#+id/stepTwo"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="#+id/stepOne"
android:layout_below="#+id/stepOne"
android:text="#string/quadEquForm"
android:textSize="18sp" />
<TextView
android:id="#+id/stepThree"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="#+id/stepOne"
android:layout_below="#+id/stepTwo"
android:text="#string/quadEquForm"
android:textSize="18sp" />

Aligning in Relatively Layouts

I have this layout inside of a RelativeLayout:
<LinearLayout
android:id="#+id/llWatchItemCommentButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/myMasterCat_Item"
style="#style/DropShadowEffect"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="99"
android:shadowColor="#ffffff"
android:text="Item"
android:textColor="#515b61"
android:textSize="22sp" />
<ImageView
android:id="#+id/bFollowComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/featured_button_selector"
android:padding="5dp"
android:src="#drawable/comment" />
</LinearLayout>
<TextView
android:id="#+id/myMastCat_Cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/llWatchItemCommentButton"
android:layout_alignLeft="#+id/llWatchItemCommentButton"
android:layout_marginLeft="10dp"
android:text="MasterCat"
android:textColor="#666"
android:textSize="16sp" />
Essentially, if that TextView in the Layout becomes two lines, it will overlap with the TextView positioned below theLinearLayout`.
Is there an attribute perhaps that could correct this? As in, I want the bottom TextView to be below the entire LinearLayout at all times, even if it begins to grow. Right now, the position appears fixed.
Have you tried the following:
<TextView
android:id="#+id/myMastCat_Cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/llWatchItemCommentButton" //add this line in
android:layout_alignBottom="#+id/llWatchItemCommentButton"
android:layout_alignLeft="#+id/llWatchItemCommentButton"
android:layout_marginLeft="10dp"
android:text="MasterCat"
android:textColor="#666"
android:textSize="16sp" />

Cannot define TextView position in RelativeLayout

When I declare 3 TextViews in RelativeLayout, 'textA', 'textB', and 'textC'. The textC should appear below textB. But when run, the textC displayed in improper position (at the top-left of screen).
I don't know can textC use android:layout_below to textB.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent" >
<TextView
android:id="#+id/textA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:text="This is TextA : " />
<TextView
android:id="#+id/textB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/textA"
android:layout_alignBaseline="#id/textA"
android:text="this is textB" />
<TextView
android:id="#+id/textC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/textB"
android:text="This is TextC" />
</RelativeLayout>
You can also change
android:layout_below="#id/textA"
to textC
The complete Example would look:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent" >
<TextView
android:id="#+id/textA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:text="This is TextA : " />
<TextView
android:id="#+id/textB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textA"
android:layout_alignBaseline="#+id/textA"
android:text="this is textB" />
<TextView
android:id="#+id/textC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textB"
android:layout_below="#+id/textA"
android:text="This is TextC" />
Just make below changes for the TextView3 :
<TextView
android:id="#+id/textC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textB"
android:layout_below="#+id/textA"
android:text="This is TextC" />
It cannot use vertical alignment to the elements that use alignBaseline to other elements. Then in this case in 'textB' change alignBaseline to be alignTop like in the code.
<TextView
android:id="#+id/textB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/textA"
android:layout_alignTop="#id/textA"
android:text="this is textB" />
Using this way it will support muti-line for textB.

Categories

Resources