Im trying to let my textview run from left to right in an infinite way.But somehow it looks really weird I even cant explain it in words so I decided to record and upload it.
Here is the video : https://www.youtube.com/watch?v=gj3FF7fEutk&feature=youtu.be
So thats how I wrote my Textview :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:layout_marginTop="20dp"
android:textColor="#color/white"
android:id="#+id/textView_title_full"
android:layout_centerHorizontal="true" />
And this TextView is in a RelativeLayout declared like this :
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="170dp"
android:id="#+id/BELOW_FULL"
android:layout_gravity="bottom"
android:background="#drawable/color_below_player_full"
android:layout_below="#+id/viewpager_albumart_full"
android:layout_alignParentBottom="true">
where the RelativeLayout is also in a Relativelayout like this :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:background="#0E0E0E">
I of course used the txt_song_title.setSelected(true); method.
How it looks like what I want to achieve :https://www.youtube.com/watch?v=o4uAA4pik68
Thank you all very much !
EDIT:
All parts where I do sth with my TextView :
public void init_textviews()
{
...
txt_song_title = (TextView)findViewById(R.id.textView_title_full);
txt_song_title.setSelected(true);
}
//init_textviews() is called in my onCreate method
txt_song_title.setText("Some Long text"); // called in onCreate after init_textviews()
And lastly:
public static void update_GUI_full (Context context) //Called when it is a button is clicked
{
...
txt_song_title.setText("longTexthere");
...
}
Working side by side with #Ahmet Kazaman we've found that there seemed to be a problem when combining a marquee TextView with another TextView periodically updated using a Handler.
After some tests we've found that this strange behaviour only happens when the TextViews are iside a RelativeLayout and everything woeks as expected when the enclosing layout is a LinearLayout. Thus, the solution (more a workaround) is to change the enclosing layout to be a Linearlayout.
Related
I set the following to visible in my onCreate method.
findViewById(R.id.noDesignsCallToAction).setVisibility(View.VISIBLE);
In the XML, the view is set to visibility gone.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical"
android:layout_below="#id/toolbar"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/go_ahead_create_something_n_it_s_really_easy_n_just_click_here_to_get_started"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/noDesignsCallToAction"
android:padding="10dp"
android:textSize="14sp"
android:typeface="sans"
android:visibility="gone"
android:onClick="LaunchCustomizer"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
Why won't the textview appear as visible in my app?
Change textColor of your textview in layout file or check if any view is not overlapping your textview.
Inflate it and then set its visibility.
setContentView(R.layout.something);
TextView tv = (TextView) findView...;
tv.setVisibility(View.VISIBLE);
and maybe string res is empty ?
Make sure you set the content view first. Otherwise you'll get an NPE as a result of the ID not being found in the active layout.
Use an instance (don't call findViewById(id).setVisibility() as it uses more memory compared to caching the TextView as a field) and then set the visibility.
setContentView(R.layout.layout);
TextView temp = (TextView) findViewById(R.id.noDesignsCallToAction);
temp.setVisibility(View.VISIBLE);
Hi everyone i got a little problem about the width of my textview
it looks like this
as you can see, my textview is bigger than my text :/
here is my code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="destinataire"
android:id="#+id/tv_destinataire"
android:layout_gravity="left|top"
android:layout_weight="1"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="envoyeur"
android:id="#+id/tv_envoyeur"
android:layout_gravity="right|top"
android:layout_weight="1"
android:layout_marginRight="25dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginBottom="10dp" />
</LinearLayout>
i would like something like this, if the message contain some word well "wrap_content" whereas is long long message something like maximum 70% of width :
thank you :)
You can reach what you said adding some logic directly on your activity and not in the XML file. You can set the width by Java code with something like:
TextView t = (TextView)findViewById(R.id.myTextView);
where myTextView is the id that you declared in your XML.
Now go ahead and write some logic...
If is necessary:
t.setWidth(200);
Note that 200 is only an example, you can calculate the width you need before.
If I were you, I might use the relative layout and add maxWidth limit to TextView containing text, and as the dialog going, just place the TextView below the last TextView and use alignStart/alightParentStart and alignEnd/alignParentEnd to indicate who's speaking.
when a new message arrives
prepare your relative layout parameter, add layout rules
set text, maxwidth limit, layout parameter and other style you want for your text
add the view to a scrollable relative layout container
Sorry for my bad English in case of you have any reading problem. :)
I am fairly experienced with Java/Eclipse, but I'm entirely new to Android development and it's proven to be quite an odd beast so far. I'm currently trying to create an application with two image buttons. My XML is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="#string/now_playing" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/StartButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/start_button"
android:contentDescription="#string/start_button" />
<ImageButton
android:id="#+id/StopButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#drawable/stop_button"
android:contentDescription="#string/stop_button" />
</LinearLayout>
</LinearLayout>
This appears to be correct, but the ImageButtons do not render properly in the Graphical Layout tab and there is a message that says, "The following classes could not be found:
- ImageButton (Change to android.widget.ImageButton, Fix Build Path, Edit XML)".
After looking around online a bit, I found that this question has popped up a few times on StackOverflow, but I was unable to find any satisfactory answers. The most common answer was to clean the project, but this has not done anything for me. Any suggestions?
Sometimes the Eclipse Graphical layout tab is unable to draw stuffs whereas the code is fine. Try to run a simple Activity with setContentView(R.layout.yourxml); and see what happen :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayout);
}
}
Post your LogCat if you still have errors.
EDIT : Oh and I didn't see :
On your second ImageButton, replace
android:text="#drawable/stop_button"
by
android:src="#drawable/stop_button"
Try to import the ImageButton class on java.
import android.widget.ImageButton;
I know that this topic is nothing new, but I really got stuck with this and tried a lot of answers and still I can't make it clear what and where should I write and use.
I have this layout file settings.xml
<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/pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="10dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/pass_del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="7dp"
android:text="Удалить пароль"
android:textAppearance="?android:attr/textAppearanceMedium" />
...
</LinearLayout>
I have TextView passdel that I want to add programmatically. Its onCreate description is passdel=(TextView) findViewById(R.id.pass_del);
And I have these methods
public void onPasSet() {
pass.setText("Сменить пароль");
((LinearLayout)passdel.getParent()).addView(passdel);
}
public void onPasDel() {
pass.setText("Установить пароль");
((LinearLayout)passdel.getParent()).removeView(passdel);
}
onPasDel is working well.
I guess Java takes current layout. So when I remove View, it's on this layout. And when I try to add this View, Java tries to find this view on current layout, but it's removed, so ..nullpointerexception. How should I write all addView stuff properly? How to point on the needed layout?
Why do you need to remove/add this View? If I understood the goal of this component correctly, the best way will be just to hide/show it:
passdel.setVisibility(View.GONE);
passdel.setVisibility(View.VISIBLE);
Of course, after you've removed passdel from ViewGroup, it has no parents anymore, so you'll get NPE while trying to call onPasSet() after onPasDel()
As you suggested, getParent() won't work intil TextView is not instantiated.
You should get Layout in different way.
You can do it by findViewById(R.id.layout.id).
Example:
In XML:
<LinearLayout
...
android:id="#+id/my_layout">
...
In Activity:
LinearLayout ll = (LinearLayout) findViewById(R.id.my_layout);
ll.addView(myView);
I have tried marquee limit 1 but it does not work
<TextView
android:id="#+id/marqueText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="1"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:gravity="center"
android:singleLine="true"
android:textSize="26sp" />
</RelativeLayout>
It seems to me that you are looking for the marquee animation. There is no XML attribute that you set for that purpose
This is a good link for the marquee animation in android. Hope it helps!
The XML attribute simply fades the textview if it goes out of your device screen.
Try using setSelected(true) method of TextView in onCreate()
TextView textView = (TextView) findViewById(R.id.marqueText);
textView.setSelected(true);