2016-05-28 5 views
0

私のJavaコードで定義されている1行に文を制限する方法を見つけることができます。私のテキストはインテントに通されます。ここで私はjavaソースファイルからテキストを1行に制限する方法は?

のVivekようこそIS-

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:id="@+id/content" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="shanky.thefirst.DisplayMessageActivity" 
tools:showIn="@layout/activity_display_message"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:id="@+id/imageView" 
     android:src="@drawable/ic_launcher"/> 

</RelativeLayout> 

マイ出力IS-

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_display_message); 

    Intent intent=getIntent(); 
    String message=intent.getStringExtra(MyActivity.EXTRA_VALUE); 
    TextView text=new TextView(this); 
    text.setTextSize(40); 
    text.setText(message); 

    RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 
      ViewGroup.LayoutParams.WRAP_CONTENT); 
    p.addRule(RelativeLayout.RIGHT_OF,R.id.imageView); 
    p.addRule(RelativeLayout.ALIGN_TOP); 


    RelativeLayout layout=(RelativeLayout) findViewById(R.id.content); 
    text.setLayoutParams(p); 
    layout.addView(text); 

    } 

マイ対応するXMLファイルwith-試してんですよ!

の代わりに- ようこそ!

+0

一行にあなたのTextViewを設定しますメッセージはそれで確認し、新しい行の文字コードに来ています。 –

+0

message.replaceAll( "\ n"、 "") – fractalwrench

+0

のようなものを使用して改行文字を削除してみてください。テキストがモバイル画面では大きすぎるため、新しい行に切り替えるだけです – Shanky

答えて

1

これはあなたが欲しいものです。ただ、やる:

text.setSingleLine(); 

それはここで

関連する問題