1

スクロールビューで中央の垂直線を描画しようとしています。Android バージョン 4.2.2 とバージョン 2.3.7 の 2 つの Galaxy 2s があります。

私の結果は、Androidバージョン4.2.2でのみ機能します

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <View
            android:layout_width="4dp"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:background="#000000" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test text" />

        </RelativeLayout>
    </FrameLayout>

</ScrollView>

例

Android バージョン 2.3.7 を使用している間、ビュー (中央の線) は描画されません。

Android 2.3.7を実行している問題を知っている人はいますか?

4

1 に答える 1

0

xml のみの解決策が見つかりませんでした。

私のxmlは次のようになります。ビューには固定の高さがあり、アクティビティで置き換えられることに注意してください。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/ManualStartTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="Start" />

        <RelativeLayout
            android:id="@+id/CenterRelativLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/ManualNoCardTableRow" >

            <View
                android:id="@+id/ManualTopGrayLine"
                android:layout_width="1dp"
                android:layout_height="200dp"
                android:layout_centerHorizontal="true"
                android:background="#000000" />

            <TextView
                android:id="@+id/ManualStepTreeHeaderTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ManualStepTreeButton"
                android:layout_marginLeft="3dp"
                android:layout_marginTop="15dp"
                android:layout_toRightOf="@+id/ManualTopGrayLine"
                android:gravity="right"
                android:text="3) Verifizieren" />

            <TextView
                android:id="@+id/ManualStepTreeBodyTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/ManualStepTreeHeaderTextView"
                android:layout_below="@+id/ManualStepTreeHeaderTextView"
                android:layout_marginLeft="3dp"
                android:text="Lorem alfpha alsda a,si ljkasoi kjasbas asdop1 ,aspo9ij aslkdja9s oaisdjas0pd oasdn0p9m asd0p9" />
        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/CenterRelativLayout"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:orientation="vertical" >

            <!-- some other content -->

        </LinearLayout>
    </RelativeLayout>

</ScrollView>

xml は次のビューを生成します。

ここに画像の説明を入力

行 (ビュー) の高さを動的に設定したい場合は、次のメソッドをアクティビティに追加できます。行の高さを RelativeLayout と同じ高さに設定します。

@Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus == true) {
            View manualTopGrayLine = findViewById(R.id.ManualTopGrayLine);
            RelativeLayout rlayout = (RelativeLayout) findViewById(R.id.CenterRelativLayout);

            RelativeLayout.LayoutParams layoutParams = (android.widget.RelativeLayout.LayoutParams) manualTopGrayLine.getLayoutParams();
            layoutParams.height = rlayout.getHeight();
            manualTopGrayLine.setLayoutParams(layoutParams);            
        }
    }
于 2013-07-10T11:15:35.373 に答える