3

一番下までスクロールすると、テキストビューにステートメントが表示されます。プロミスのテキストビューが大きくなりすぎたようです。それを修正する方法はありますか?

スクリーンショット 星の下のすべては、promis textview の一部です。複数の改行文字を含む単一の文字列です スクリーンショット2別のスクリーンショット

promise を生成するコード

prm = doc.getElementsByTagName("promise");
            for (int j = 0; j < prm.getLength(); j++) {
                prom += parser.getValue(e, KEY_PROMISES, j) + "\n";

            }
            prom.substring(0,prom.lastIndexOf('\n'));

レイアウト

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget32"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/top"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/face"
            android:layout_width="68dp"
            android:layout_height="68dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" />

        <TextView
            android:id="@+id/name"
            android:layout_width="243dp"
            android:layout_height="35dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@id/face"
            android:text="from" />

        <TextView
            android:id="@+id/office"
            android:layout_width="242dp"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/face"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/name"
            android:layout_toRightOf="@id/face"
            android:text="subject" />
    </RelativeLayout>

    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/top"
        android:numStars="6"
        android:singleLine="false" />

    <TextView
        android:id="@+id/promises"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/ratingBar1"
        android:layout_marginTop="5dp"
        android:text="TextView" />

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/promises"
        android:layout_marginRight="22dp"
        android:layout_marginTop="26dp" >

        <TextView
            android:id="@+id/statement"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />
    </ScrollView>

</RelativeLayout>

アプリのアクティビティ

public class SingleMenuItemActivity  extends Activity {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.candidate);
        Log.d("here ?", "No ");
        int loader = R.drawable.loader;
        // getting intent data
        Intent in = getIntent();
        Log.d("here ?", "No ");
        // Get XML values from previous intent
        String name = in.getStringExtra("name");
        Log.d("Name ", name);
        Log.d("here ?", "No ");
        DatabaseHandler db = new DatabaseHandler(this);
        Log.d("here ?", "No ");
        Candidate p = db.getCandidate(name);
        Log.d("Did i take candidate? ", "yea ");
        db.close();
        Log.d("Statement", p.get_statment());
        // Displaying all values on the screen
        TextView lblName = (TextView) findViewById(R.id.name);
        TextView lblOffice = (TextView) findViewById(R.id.office);
        TextView lblPromise = (TextView) findViewById(R.id.promises);
        TextView lblStatement = (TextView) findViewById(R.id.statement);
        ImageView lblFace = (ImageView) findViewById(R.id.face);
        RatingBar lblRating = (RatingBar) findViewById(R.id.ratingBar1);
        ImageLoader imgLoader = new ImageLoader(this);
        lblName.setText(p.get_name());
        lblOffice.setText(p.get_office());
        lblPromise.setText(p.get_promises());
        lblStatement.setText(p.get_statment());
        lblRating.setRating(p.get_ranking());
        imgLoader.DisplayImage(p.get_photograph(), loader, lblFace);

    }
}

logcat によると、p.get_statment() には適切な値が含まれています

12-16 05:07:16.089: D/Statement(279): I strive for the highest standards of appearance and personal grooming.  If, like me, you think that the University's reputation is being dragged down by lecturers who have little or no regard for fashion and are content to wear ill-fitting or patched clothes then vote for me: the stylish choice.

評判が低すぎて画像を投稿できません %)

4

3 に答える 3

3

RatingBarがstatementTextViewをカバーしているようです。

<RatingBar
    android:layout_above="@+id/statement"
    ... />

おそらくあなたは意味しましたlayout_belowか?

また、promisesTextViewの上部マージンが非常に大きいため、statementTextViewが画面の下部から押し出されている可能性があります。

<TextView
    android:id="@+id/promises"
    android:layout_marginTop="124dp"
    ... />

追加どうやら、 TextView
の最後にいくつかの改行文字もあります。promisesソースからこれらの文字を削除できない場合は、次を使用できますtrim()

prom = prom.trim();
于 2012-12-16T05:43:42.603 に答える
2

あなたのコードは正しいようです。id lblStatementの textViewにテキストが表示されない場合は、テキストを識別できない背景があるか (色を変更してみてください)、テキストビューの位置に対してマージンが不十分である可能性があります。

の値p.get_statment()が正しい場合、他に考えられる理由はありません。

于 2012-12-16T05:33:51.410 に答える
0

OK、解決策を見つけました。textviewが拡張された理由がわからないのに加えて、今すぐ修正する方法を知っています:)まず、行数を知る必要があります。どの文字列が生成されるかを知る必要があります。

private static int countLines(String str){
           String[] lines = str.split("\r\n|\r|\n");
           return  lines.length;
        }

次に、テキストビューのサイズを制限します

lblPromise.setMaxLines(countLines(p.get_promises()));
于 2012-12-17T08:17:31.370 に答える