I have textview with specific height and i have so many sentences within that textview. I have implemented scrollbar within that textview to see whole content. But i want to implement auto scroll and i am not getting the way to implement this auto scroll.
Here is my xml Layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1"
>
<TextView
android:id="#+id/lyricView"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:width="200dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:gravity="center"
android:maxLines="16"
android:scrollbars = "vertical"
android:paddingTop="8dp"
android:paddingBottom="5dp"
android:layout_marginTop="67dp"
android:background="#80000000"
/>
</LinearLayout>
Please help me to solve my problem. Thanx.
I did something like this
android:text=" Please take your belongings after check out."
android:singleLine="true"
android:textColor="#000000"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:layout_marginTop="150dp"
android:scrollHorizontally="true"
android:id="#+id/TextView03"
android:padding="5dip"
android:textSize="55dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
I think the 'marquee' funda is missing........
an example :
public class TextViewMarquee extends Activity {
private TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) this.findViewById(R.id.tv);
tv.setSelected(true); // Set focus to the textview
}
}
in the XML :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/mywidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="this is a very long piece of text that will move" />
</RelativeLayout>
This is working for me as you needed.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/lyricView"
android:layout_width="200dp"
android:layout_height="250dp"
android:layout_marginTop="67dp"
android:background="#80000000"
android:scrollbars="vertical"
android:text="#string/extra"
android:textColor="#ffffff"
android:textStyle="bold" />
</ScrollView>
</LinearLayout>
If you want to hide scroll then use this android:scrollbars="none".
Related
I have a xml with a ScrollView and a LinearLayout as a child of ScrollView.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewStub
android:id="#+id/social_empty_stub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:inflatedId="#+id/social_empty_stub_inflted"
android:layout="#layout/empty_screen"
android:visibility="gone" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/activity_stream"
android:background="#DCDCDCDC"
android:fadingEdge="none" >
<LinearLayout
android:id="#+id/activity_stream_wrap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
and I have another xml with a LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<!-- List Item on activity stream -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout_Activity_Streams"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp" >
<!-- Avatar -->
<com.example.bb.ShaderImageView
android:id="#+id/imageView_Avatar"
android:layout_width="#dimen/social_avatar_size"
android:layout_height="#dimen/social_avatar_size"
android:layout_marginLeft="5dp"
android:scaleType="fitXY" />
<!-- Content -->
<LinearLayout
android:id="#+id/relativeLayout_Content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="5dp"
android:background="#drawable/news_browser_background_shape"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="#+id/textView_Name"
style="#style/textview_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:maxLines="5"
android:textStyle="bold" />
<TextView
android:id="#+id/textView_Message"
style="#style/textview_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="3dip"
android:maxLines="5" />
<TextView
android:id="#+id/textview_temp_message"
style="#style/textview_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="3dip"
android:maxLines="5"
android:visibility="gone" />
<ViewStub
android:id="#+id/attached_image_stub_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="2dp"
android:inflatedId="#+id/attached_image_stub_inflate"
android:layout="#layout/activity_image_display_layout"
android:padding="5dp"
android:visibility="gone" />
<TextView
android:id="#+id/activity_comment_view"
style="#style/textview_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="3dip"
android:maxLines="5"
android:visibility="gone" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginRight="10dp"
android:layout_marginTop="7dp"
android:gravity="center_vertical">
<ImageView
android:id="#+id/activity_image_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/ImageDesc"
android:layout_marginLeft="5dp"
android:padding="2dp"
android:scaleType="fitXY" />
<!-- Time text view -->
<TextView
android:id="#+id/textView_Time"
style="#style/textview_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/activity_image_type"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:layout_marginRight="3dp" />
<!-- Comment button -->
<Button
android:id="#+id/button_Comment"
style="#style/textview_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/social_activity_browser_comment_button_shape"
android:gravity="center_vertical"
android:padding="2dp" />
<!-- Like button -->
<Button
android:id="#+id/button_Like"
style="#style/textview_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/button_Comment"
android:background="#drawable/social_activity_browser_like_button_shape"
android:gravity="center_vertical"
android:padding="2dp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Now I want to add the LinearLayout in second xml programmatically in ScrollView of first xml. I am using following code
setContentView(R.layout.activitybrowserview);
View view = LayoutInflater.from(context).inflate(R.layout.activitybrowserviewcell, null);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.RelativeLayout_Activity_Streams);
ScrollView sv = (ScrollView) findViewById(R.id.activity_stream);
sv.addView(ll);
I get following error, how can I avoid that. I don't understand the error.
IllegalStateException "Scrollview can host only one direct child"
Scrollview can host only one direct child,the scrollvie has direct child yet(android:id="#+id/activity_stream_wrap"),u should add view with this one.
setContentView(R.layout.activitybrowserview);
View view = LayoutInflater.from(context).inflate(R.layout.activitybrowserviewcell, null);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.RelativeLayout_Activity_Streams);
LinearLayout parentLl = (LinearLayout ) findViewById(R.id.activity_stream_wrap);
parentLl .addView(ll);
In your first XML file you have
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/activity_stream"
android:background="#DCDCDCDC"
android:fadingEdge="none" >
<LinearLayout
android:id="#+id/activity_stream_wrap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
If you remove the <LinearLayout> here, then you can add another LinearLayout instead. You can either remove it directly from the XML file or remove it programatically.
Just add a Linear Layout as a container to your current LinearLayout and the LinearLayout that you want to add pragmatically. I think this should solve your problem. ScrolView Can contain only one child as the exception says the same.
<ScrolView>
<LinearLayout> this will be the container
<linearlayout> the one that is currently in the first xml file
</LinearLayout>
</LinearLayout>
</ScrolView>
Hope this will help.
setContentView(R.layout.activitybrowserview);
View view = LayoutInflater.from(context).inflate(R.layout.activitybrowserviewcell, null);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.RelativeLayout_Activity_Streams);
ScrollView sv = (ScrollView) findViewById(R.id.activity_stream);
sv.removeAllViews();
sv.addView(ll);
Yes, this is yet another edittext grow question on SO. And yes I've already gone through all those edittext grow questions. But this ones a bit specific.
UI:
A simple android layout with edittext and button below it. When text is less, the edittext view is still covering whole screen leaving space for button below.
Once user starts entering text, edittext grows vertically to accommodate text. At the same time, the button should also kept pushing downwards to let edittext grow.
User can vertically scroll through screen to view full text.
UI after entering significant text:
Here's the layout with edittext and button below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background"
android:clipToPadding="false"
android:fadingEdge="none"
android:fillViewport="true"
android:padding="13dp"
android:scrollbarStyle="outsideOverlay" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<!-- some fixed width image -->
<ImageView
android:id="#+id/someimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:src="#drawable/page_white_text" />
<EditText
android:id="#+id/some"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/someimage"
android:background="#null"
android:gravity="top"
android:minLines="10"
android:minHeight="50dp"
android:textColor="#222222"
android:textSize="15dp"
android:typeface="serif" >
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:baselineAligned="true"
android:layout_marginTop="5dp"
android:padding="10dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
This works more or less. But when I enter to much text, instead of pushing button downwards. It goes behind it like:
Any help here is much appreciated. Thanks :)
Here's my recommendation: inside the ScrollView, put a RelativeLayout in which you can place every element in a certain order using android:layout_below. For the auto-growing of your EditText, use this solution.
Let's see an example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<RelativeLayout
android:id="#+id/general2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20sp" >
<TextView
android:id="#+id/textFirstOpinion"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/titleFirstOpinion"
android:textStyle="bold"
android:textSize="23sp"
android:textColor="#FFFFFF"
android:layout_marginTop="10dp" />
<EditText
android:id="#+id/fieldFirstOpinion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textFirstOpinion"
android:minHeight="80sp"
android:isScrollContainer="true"
android:inputType="textMultiLine"
android:textSize="20sp"
android:gravity="top|left" />
<Button
android:id="#+id/button"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_below="#id/fieldFirstOpinion"
android:layout_centerHorizontal="true"
android:layout_marginTop="37sp"
android:textSize="23sp"
android:text="#string/textSendButton"
android:gravity="center_horizontal"
android:padding="10dp" />
</RelativeLayout>
</ScrollView>
try adding android:layout_below="#id/some" in your LinearLayout like
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:baselineAligned="true"
android:layout_marginTop="5dp"
android:padding="10dp"
android:orientation="vertical"
android:layout_below="#id/some" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Since you want the button to be at the bottom of the page, add the following line
android:layout_below="#+id/some"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
in your LinearLayout code here like
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/some"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:baselineAligned="true"
android:layout_marginTop="5dp"
android:padding="10dp"
android:orientation="vertical" >
Also make sure the layout:height parameter of EditText is set to wrap_content
Try this and tell me if it works or not
when i try to set the text of an textview i get a nullpointerexception. somehow the findviewbyid method return null but i dont know why.
this is my xml file:
<?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="wrap_content" >
<RelativeLayout
android:id="#+id/rl_ros_layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#+id/tv_ros_view1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ProgressBar
android:id="#+id/pb_ros_bar1"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:visibility="invisible" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_ros_layout1" >
<TableLayout
android:id="#+id/tl_rostertable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:stretchColumns="2" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="#string/team" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="#string/pos" />
<TextView
android:layout_height="wrap_content"
android:padding="3dp"
android:text="#string/name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="3dp"
android:text="#string/score" />
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
and my oncreate method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.roster);
final Bundle extra = getIntent().getExtras();
position = extra.getInt("pos");
int id = de.damps.fantasy.HomeActivity.ID[position];
url = de.damps.fantasy.HomeActivity.URL + "/roster/2011/" + id;
tbl = (TableLayout) findViewById(R.id.tl_rostertable);
team = (TextView) findViewById(R.id.tv_ros_view1);
String s= de.damps.fantasy.HomeActivity.TEAMS[position];
team.setText(s);
new GetRoster().execute(url);
}
the tablelayout is found without any problmes. but the textview is null.
i already cleaned the project but it didnt solve the problem
would be nice if someone can help me
You have a typo:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:id="#+id/tv_ros_view1"
android:textAppearance="?android:attr/textAppearanceMedium" />
(android:text instead of android:id)
You wrote
android:text="#+id/tv_ros_view1"
instead of
android:id
you create ID your text view like this android:id="#+id/tv_ros_view1" in place of android:text="#+id/tv_ros_view1" this is use full to you.
In you xml layout:
android:text="#+id/tv_ros_view1"
should be:
android:id="#+id/tv_ros_view1"
the text attribute is used to tell textview what text to show.
In your faulty/first text view you have written like this:
android:text="#+id/tv_ros_view1"
Just replace this with this:
android:id="#+id/tv_ros_view1"
This is how you have to assign id to a view(TextView).
I am doing an application in which I have a textview and an image view inside a LinearLayout. Touching the linear layout takes us to another activity. As the text wont fit inside the textview, I want to make the textview content marquee. I have tried may methods but it is not working. The xml content is given below.
<LinearLayout
android:id="#+id/profile_pic_Layout"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:layout_margin="10dip"
android:background="#color/blue_background" >
<ImageView
android:id="#+id/profile_pic_menu"
android:layout_width="100dip"
android:layout_height="100dip"
android:contentDescription="#string/image"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/profile_name_text"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:layout_gravity="bottom"
android:gravity="center"
android:marqueeRepeatLimit="1"
android:inputType="text"
android:lines="1"
android:duplicateParentState="true"
android:scrollHorizontally="true"
android:fadingEdge="horizontal"
android:focusable="true"
android:textColor="#android:color/white"
android:textSize="20sp">
<requestFocus android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true" />
</TextView>
</LinearLayout>
I have also tried setting the textview selected in the code by using,
profileNameTextView.setEllipsize(TruncateAt.MARQUEE);
profileNameTextView.setSelected(true);
I think the it is because, the the parent linearlayout is having the focus.
Please help me fix this issue..!
Thank you all in advance..!
Apparently you are missing the android:ellipsize="marquee" attribute
Here's a minimalistic working example:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:marqueeRepeatLimit="1"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="HELLO HOW ARE YOU WHAT ARE YOU DOING TEST ANDROID IS WRITING TO YOU." />
public class TextViewMarquee extends Activity {
private TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) this.findViewById(R.id.mywidget);
tv.setSelected(true); // Set focus to the textview
}
}
The xml file with the textview:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/mywidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use marquee, with a long text" />
I'm trying to make a list of LinearLayout become VISIBLE at a click on a "header" LinearLayout.
<LinearLayout android:id="#+id/sample_title" ...>
<TextView ... />
</LinearLayout>
<LinearLayout
android:id="#+id/sample_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:orientation="horizontal"
android:visibility="visible" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:text="Sample text 1"
android:textColor="#color/white" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:orientation="horizontal"
android:visibility="visible" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:text="Sample text 2"
android:textColor="#color/white" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</LinearLayout>
Programmatically:
mSampleTitle = (LinearLayout) mView.findViewById(R.id.sample_title);
mSampleTitle.setOnClickListener(this);
mSampleContent = (LinearLayout) mView.findViewById(R.id.sample_content);
[...]
public void onClick(View v) {
if (v == mSampleTitle) {
mSampleContent.setVisibility(mSampleContent.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
}
}
It works fine when there is only one TextView to show, but as soon as there is more, only the first one becomes visible and all the rest is just blank space.
Thank you
My bad, stupid error.
I forgot the android:orientation="vertical". The code changing the VISIBILITY works fine.
<LinearLayout
android:id="#+id/sample_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<LinearLayout
android:id="#+id/sample_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" >
I still find weird the fact that they were so much blank space below that LinearLayout horizontal...