Put a TextView in front of a ImageView - java

Im searching a way how to fix a TextView on a ,for example, transparent square like in the Picture I did in Paint.net .So the TextView should in front of the transparent square (ImageView).Also it should stretch when the screen is bigger.
http://www7.pic-upload.de/22.02.14/24vtze5ulxc2.png
How can I solve the problem ?
Thanks !

Use a FrameLayout
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/semi_transparent_background"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is my text."/>
</FrameLayout>
Alternatively, you could do something similar with a relative layout.

You can use RelativeLayout or FrameLayout for that.
<FrameLayout>
<ImageView>
<TextView>
</FrameLayout>
Your textview will appear on ImageView.
Although note that, RelativeLayout has double taxation tradeoff. Each measure and layout happens twice.

Simply ordering the items in RelativeLayout from top to bottom in the XML will make each in turn move to the front compared to the others above it.

Related

How to make a layout in android that sticks to the bottom of the screen until the scrollview is scrolled to a certain position it gets scroll too?

I want to make a android activity screen where a layout is sticked to bottom until scrollview get scroll to a certain position. like in this video samples links:
https://drive.google.com/open?id=0B14wNBitoI33LWtUNThqcXRIUWc
https://drive.google.com/open?id=0B14wNBitoI33QW1BOGR1di1TcGc
amarjain07's StickyScrollView maybe a solution you would want to look into. His methodology of assigning the "sticky" views as identified attributes in the layout xml is quite a nifty feature IMHO.
Use a RelativeLayout and put the Button-Container inside it.
Pass the container in your_scrollview_activity.xml the following attribute
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1 (reft)" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2 (right)"/>
</LinearLayout>
</RelativeLayout>
NOTE: You need to set a listener in your activity to get the ScrollViews current position / current height. With this current height you can calculate the "left space" to the bottom / end of the ScrollView. If your RelativeLayout reaches the bottom or if it's close to the bottom AND within the visible area, then call your animation.

How to show a TextView inside a LinearLayout that is "visibility="gone""

i'm actually really new at coding in java and on AndroidStudio and i'm trying to update an application that already exist.
I have 3 LinearLayout that look like 3 square inside each other and inside the last one, i have a TewtView.
the first one is the main one and is always visible.
When i put my two last LinearLayout in visibility="GONE" my LinearLayout disapear, and i want that my textView will be always visible, even if the LinearLayout that contains it are invisible.
It is possible?
<LinearLayout
style="#style/ColPlayer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
style="#style/SquareBogey"
android:visibility="gone"
android:layout_width="70dp"
android:layout_height="50dp"
android:orientation="horizontal"
android:id="#+id/outersquare">
<LinearLayout
style="#style/SquareBogey"
android:visibility="gone"
android:layout_width="60dp"
android:layout_height="40dp"
android:orientation="horizontal"
android:id="#+id/innersquare">
<TextView
android:id="#+id/PlayerCJ01"
style="#style/ColCJPlayer"
android:layout_height="wrap_content"
android:ems="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Just ask me if you need more informations.
Thanks
When setting the visibility of a parent layout to GONE or INVISIBLE, all its children will also become GONE or INVISIBLE.
If you want to show the TextView but not its parent LinearLayout, than you could either move the TextView out of the LinearLayout, or you could remove the styling of the LinearLayout so it will look like its gone, but obviously it's still there.
Setting the visibility of the LinearLayout to GONE and its child TextView's visibility to VISIBLE won't work and therefore is not an option.
Instead of setting the visibility as GONE for the LinearLayouts, maybe you can set their background/border as transparent by changing their style.
It depends on your use case, if it suits your need.

android custom round layout

I want to make something like the image in the link, so I've two tabs at the bottom and a round button in the middle in front of these tabs, and a fragment that in the image is the blue background.
So I can make the tabs and the fragment just fine. but how can I put the round button in front of the tabs and the fragment?
Check this image
thanks
By using FrameLayout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="200dp"
android:layout_width="200dp"/>
<Button
android:text="Frame"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"/>
</FrameLayout>
Now button is in front of The Image.
You can add layout_marginTop attribute to the view you would want to be in front of the Fragment. Example
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="200dp"
android:layout_width="200dp"
android:layout_marginTop="-100dp"/>
This will move the ImageView 100dp upwards in front of the Fragment. Hope it helps

How can I add an image immediately to the right of the text in a FrameLayout wrapper, which holds one of two dynamically sized TextViews?

I have a FrameLayout which is a wrapper for a TextView. The TextView can be either one of two TextView objects with dynamically modified text. I would like to add an image immediately to the right of the text contained in the FrameLayout. I have tried two things:
I set up the FrameLayout inside a RelativeLayout. I added an ImageView:
<RelativeLayout>
<!-- Two TextViews Here -->
<FrameLayout
android:id="#+id/my_frame_layout"
android:layout_width="match_parent"
...
/>
<ImageView
android:id="#+id/my_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/my_frame_layout"
/>
</RelativeLayout>
This worked the first time the layout was loaded. However, when the text contained in the FrameLayout changed, the image stayed at its originally calculated position, rather than recalculating to stay to the right of the TextView.
So I tried making it a drawable and setting it in code. I fetched the TextView held in the FrameLayout, and called:
setCompoundDrawablesWithIntrinsicBounds(0,0,myDrawable,0)
This worked well, except that the drawable is always to the furthest right point of the FrameLayout, despite the TextView being only half full. I want the image to be immediately to the right of the text.
Does anyone have any other suggestions I could try to make this happen?
I ended up wrapping the ImageView in an additional LinearLayout, like so:
<LinearLayout
android:id="#+id/my_image_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="my_frame_layout"
android:gravity="left|center_vertical"
>
<ImageView
android:id="#+id/my_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Unlike the ImageView alone, the LinearLayout is redrawn when the text changes size, so this worked for me.

Force an EditText to scroll down to a certain spot

How would I make an multi-line EditText with a vertical scroll bar go down to a certain spot? I want to do this inside of the Java code, and I'd prefer to do it with an EditText, but I'd be willing to use a ScrollView if I need to.
The EditText XML:
<EditText
android:id="#+id/theTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textAutoCorrect|textMultiLine"
android:scrollbars="vertical"
android:width="0dp" >
You can try using scrollTo api from the view.

Categories

Resources