2

私が抱えている問題は、2行にまたがるTextView右側の2番目を揃えることです。TextView

を使用していますRelativeLayoutが、使用するlayout_toRightOfと画面上部に表示され、追加するlayout_alignRightと消えます。

私はこれがどのように機能するか非常に混乱しています。あなたはそれが最初のTextView終わりに続くと思いますが、そうではありません。ああ、それwrap_contentが問題だと誰かが思った場合に備えて、幅と高さを使用しています。前もって感謝します。

XML

<TextView 
            android:id="@+id/edit_event_name_show"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18dp"
            android:textStyle="bold"
            android:layout_marginBottom="5dp"
            android:scrollHorizontally="false"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true" />
        <TextView 
            android:id="@+id/show_event_type"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10dp"
            android:scrollHorizontally="false"
            android:layout_toRightOf="@+id/edit_event_name_show"
            android:layout_alignBaseline="@+id/edit_event_name_show" />

編集:TextViewsで物事をうまく調整しようとして同様の問題を抱えている人には、デフォルトで方法はありません。ただし、を使用SpannableStringしてそれらを使用および構築できますSpannableStringBuilder

4

3 に答える 3

3

3回目の試行(成功した試行)

これはあなたを助け、他のものよりもはるかに簡単になると私は信じています。

このリファレンスを使用してみてください。ただし、色ではなくフォントサイズを変更してください。

サムの答えはリンクを要約しています。(ある時点でリンクが停止した場合。)

2回目の試行

<?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" >

    <TextView
        android:id="@+id/edit_event_name_show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:scrollHorizontally="false"
        android:text=" test 1     jfalksjdflkjasdfj"
        android:textSize="18dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/show_event_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/edit_event_name_show"
        android:layout_alignParentRight="true"
        android:scrollHorizontally="false"
        android:text="test2          adjfalsjdfla fa sdfasdf asf a"
        android:textSize="10dp" />

</RelativeLayout>

写真:

ここに画像の説明を入力してください


最初の試み

で囲んTextViewsでみませんかLinearLayout。それはそれらをよりよく整理し、少しきれいに保つでしょう。

これを試して、どうなるか教えてください:

<?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" >

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

        <TextView
            android:id="@+id/edit_event_name_show"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollHorizontally="false"
            android:text="test1"
            android:textSize="18dp"
            android:textStyle="bold"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/show_event_type"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollHorizontally="false"
            android:text="test2"
            android:textSize="10dp"
            android:layout_weight="1" />
    </LinearLayout>

</RelativeLayout>

写真:

ここに画像の説明を入力してください


長いテキストの場合:

ここに画像の説明を入力してください

于 2012-07-18T23:20:39.973 に答える
3

Spannablesの使用

Spannablesをいじるために会話を離れ、これを作成しました。

public class Example extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView textView = new TextView(this);
        textView.setTextSize(18);

        String first = "A sentence that contains enough balderdash, blather and babble to wrap at least once.";
        String second = " (Normal)";

        Spannable span = new SpannableString(first + second);
        span.setSpan(new StyleSpan(Typeface.BOLD), 0, first.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        span.setSpan(new RelativeSizeSpan(0.7f), first.length(), span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        textView.setText(span);
        setContentView(textView);
    }
}

しかし、prolink007はすでにあなたに一般的なリンクを与えています...まあ。とにかく投稿します。

于 2012-07-18T23:16:20.900 に答える
-1
<?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="match_parent">

    <TextView
        android:id="@+id/news_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:singleLine="true"
        android:ellipsize="end"
        android:textSize="30sp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="10dp"
        android:textStyle="bold"
        android:text="hiangdnfaljiadnk" />

    <TextView
        android:id="@+id/news_summary"
        android:paddingTop="5dp"
        android:layout_below="@id/news_title"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"             android:text="hiangdnfaljiadnkfjfaingaldnfasidognkahiangdnfaljiadnkfjfaingaldnfasidognkahiangdnfaljiadnkfjfaingaldnfasidognka"
    />

    <TextView
        android:id="@+id/news_from"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:layout_below="@id/news_summary"
        android:layout_alignParentLeft="true"
        android:textSize="20sp"
        android:text="1111111" />

    <TextView
        android:id="@+id/news_comment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingRight="10dp"
        android:layout_below="@id/news_summary"
        android:layout_alignParentRight="true"
        android:textSize="20sp"
        android:text="3333333" />

</RelativeLayout>

写真

于 2015-12-18T04:42:11.783 に答える