2017-09-22 6 views
0

タイトルと閉じるボタンでダイアログがポップアップしています。これはXMLです:あなたはTextViewにはそれがマーキーのために必要なすべてのものを持って見ることができると同様マーキーとlayout_weightがスクロールしていないAndroid TextView

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:gravity="center_vertical"> 

    <TextView 
     android:id="@+id/text_title" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_marginLeft="24dp" 
     android:layout_marginRight="0dp" 
     android:layout_marginTop="16dp" 
     android:layout_marginBottom="16dp" 
     android:maxLines="1" 
     <!--- android:singleLine="true" <-- Do not comment about this, it is deprecated ---> 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:scrollHorizontally="true" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:textSize="20sp" 
     android:textColor="@android:color/black" 
     /> 

    <ImageView 
     android:id="@+id/backburger" 
     android:layout_width="32dp" 
     android:layout_height="32dp" 
     android:layout_marginStart="24dp" 
     android:layout_marginEnd="24dp" 
     android:layout_marginTop="16dp" 
     android:layout_marginBottom="16dp" 
     android:src="@drawable/ic_close" 
     android:foreground="?android:attr/selectableItemBackground" 
     /> 

</LinearLayout> 

は、singleLineオプションは廃止されましたので、私はそれを使用することはできません。私はJavaのsetSelected(true)を呼び出します。マーキーについては多くの質問がありますが、layout_weightと'17 'はありません。

これは、XMLのプレビューです:

Output

+0

ここに私の答えhttps://stackoverflow.com/a/46360549/5381331を確認してください。 layout_weightでテストしたので、この問題は 'android:layout_weight'とは関係ありません。またhttps://stackoverflow.com/a/12005799/5381331を参照してください –

答えて

1

、このいずれかを試してください:あなたのXMLで :

<TextView 
     android:id="@+id/text_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:maxLines="1" 
     android:ellipsize="marquee" 
     android:fadingEdge="horizontal" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:scrollHorizontally="true" 
     android:textSize="20sp" 
     android:textColor="@android:color/black" /> 

とあなたのコード:

tv = (TextView) this.findViewById(R.id.text_title); 
tv.setSelected(true); 

希望の助け:)

+0

回答ありがとうございますが、これは私のためには機能しませんでした。 –

+0

@Finioxあなたの質問は混乱しています。私はあなたの要件を理解することができません。あなたの要件をはっきりと説明してください。あなたは出力として何をしたいですか? –

+0

この行を追加した後に試してくださいtv.requestFocus(); – Rajasekhar

0
public void setticker(String text, TextView view) { 
    if (text != "") { 


     view.setText(text); 
     //view.setTextSize(25.0F); 
     Context context = view.getContext(); // gets the context of the view 

     // measures the unconstrained size of the view 
     // before it is drawn in the layout 
     view.measure(View.MeasureSpec.UNSPECIFIED, 
       View.MeasureSpec.UNSPECIFIED); 

     // takes the unconstrained width of the view 
     float width = view.getMeasuredWidth(); 
     float height = view.getMeasuredHeight(); 

     // gets the screen width 
     float screenWidth = ((Activity) context).getWindowManager() 
       .getDefaultDisplay().getWidth(); 

     // view.setLayoutParams(new LinearLayout.LayoutParams((int) width, 
     //  (int) height, 1f)); 

     System.out.println("width and screenwidth are" + width + "/" 
       + screenWidth + "///" + view.getMeasuredWidth()); 

     // performs the calculation 
     float toXDelta = width - (screenWidth - 0); 

     // sets toXDelta to -300 if the text width is smaller that the 
     // screen size 
     if (toXDelta < 0) { 
      toXDelta = 0 - screenWidth;// -300; 
     } else { 
      toXDelta = 0 - screenWidth - toXDelta;// -300 - toXDelta; 
     } 
     // Animation parameters 
     Animation mAnimation = new TranslateAnimation(screenWidth, 
       toXDelta, 0, 0); 
     mAnimation.setDuration(15000); 
     mAnimation.setRepeatMode(Animation.RESTART); 
     mAnimation.setRepeatCount(Animation.INFINITE); 
     view.setAnimation(mAnimation); 
     //parent_layout.addView(view); 
    } 
} 
+0

これはマーキーをカスタムアニメーターに置き換えますか?問題が1つしかない、TextViewが入る 'MaterialDialog'があります。これは' float screenWidth'が大きすぎることを意味します。 –

+0

はい、それは画面の幅の幅が広すぎます。ダイアログの幅で計算してみてください –

関連する問題