2013-07-07 1 views
0
<HorizontalScrollView 
android:layout_width="fill_parent" 
android:layout_height="0dp" 
android:layout_weight="1" 
android:scrollbars="none"> 
<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:singleLine="true" 
    android:text="" 
    android:layout_gravity="right" 
    android:gravity="right|center_vertical" 
    android:textColor="#666666" 
    android:textSize="30sp" /> 
</HorizontalScrollView> 

안녕하세요, 사용 가능한 모든 공간을 채울 때 textView 내의 텍스트를 스크롤 가능하게하고 싶습니다. 텍스트가 오른쪽에서 삽입되므로 텍스트의 시작 부분이 왼쪽에 사라집니다. 그것이 스크롤 할 때 스크롤 할 수있는 공간의 양을 스크롤 할 수있는 텍스트의 공백을 표시 할 수 있지만 오른쪽으로 스크롤합니다, textView 비어 있으며 내가 전에 입력 한 도달 할 수 없습니다. 제안? 영어가 불쌍해서 죄송합니다. 충분히 분명 소원 ...ScrollView 문제 Android

답변

0

이동 안드로이드합니다 (있는 ScrollView가 수직있는 LinearLayout의 일부입니다) : Activity.java 쓰기에서
전용 "center_vertical"에
변경 텍스트 뷰 중력을 HorizontalScrollView하는 텍스트 뷰에서 layout_gravity = "오른쪽" TextView에 텍스트를 설정하고 모든 것을 오른쪽으로 스크롤하는 메소드.
TextView에서 텍스트를 설정하려면이 방법을 사용하십시오.

예제 코드 :

XML

<HorizontalScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:scrollbars="none" 
    android:layout_gravity="right"> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:singleLine="true" 
    android:text="" 
    android:gravity="center_vertical" 
    android:textColor="#666666" 
    android:textSize="30sp"/> 

</HorizontalScrollView> 

<Button 
    android:id="@+id/button1" 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:text="ClickMe" 
    android:onClick="btClick"/> 

</LinearLayout> 

Activity.java :이 당신을 위해 무엇을 물어이었다 희망

public class MainActivity extends Activity { 

    private TextView textView; 
    private HorizontalScrollView scroll; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     scroll = (HorizontalScrollView)findViewById(R.id.scrollView); 
     textView = (TextView) findViewById(R.id.textView2); 

     SetTextViewText("Inicial Text"); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    public void btClick(View v) { 

     String text = textView.getText().toString(); 
     int rnd = 1 + (int)(Math.random() * ((9 - 1) + 1));//Get a random number between 1 and 9 
     text += rnd; //Append random to previous text 
     SetTextViewText(text); //Set TextView with new text; 
    } 

    private void SetTextViewText(String text)// Set text to TexView and scroll all to the right 
    { 
     textView.setText(text); 
     scroll.post(new Runnable() { 
      public void run() { 
       scroll.fullScroll(ScrollView.FOCUS_RIGHT); 
      } 
     });  
    } 
} 

.

+0

네, 효과가있었습니다. 고마워, 너 정말로 나를 도왔다. – user2557804