-1

mDocView は、あたかも他のものの上にあるかのように cramperView に重なっています。topHeader の下に mDocView が必要です。

私のcramper.xml-

<ViewSwitcher
    android:id="@+id/switcher"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" >

    <Button
        android:id="@+id/backfromreport"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:background="@drawable/btn_black_xml"
        android:padding="10dp"
        android:text="Back"
        android:clickable="true"
        android:onClick="goBack"

        android:textColor="#ffffff"
        android:textSize="16dp" />

    <TextView
        android:id="@+id/messager"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Messager"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textStyle="bold" />

</LinearLayout>
</ViewSwitcher>

関連する Cramper Java ファイル:

private View cramperView;
private LinearLayout   topHeader;

@Override
public void onCreate(Bundle savedInstanceState)
{
   super.onCreate(savedInstanceState);
topHeader = (LinearLayout) findViewById(R.id.linearLayout1);
private ReaderView   mDocView = new ReaderView(this); //ReaderView extends AdapterView
cramperView= getLayoutInflater().inflate(R.layout.cramper,null);
RelativeLayout layout = new RelativeLayout(this);
layout.addView(cramperView);
layout.addView(mDocView);
setContentView(layout);
4

2 に答える 2

0

ビューのレイアウト パラメータを追加する

RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT,
            RelativeLayout.LayoutParams.FILL_PARENT);
rlp.addRule(RelativeLayout.BELOW, R.id.linearLayout1); 
mDocView.setLayoutParams(rlp);

layout.addView(cramperView);
layout.addView(mDocView);
setContentView(layout);
于 2013-05-03T12:25:28.303 に答える
0

あなたが言ったように、あなたはafterを使用してViewSwicherいるので、 cramperレイアウトの後に常に追加されます (これは AdapterView を拡張します) 。RelativeLayoutlayout.addView(mDocView)layout.addView(cramperView)ReaderView

解決策は次のとおりです。

xml ファイルにRelativeLayoutafterを追加します。</ViewSwitcher>このような:

    <RelativeLayout
        android:id="@+id/docViewLayout"
        android:layout_width="1190dp"
        android:layout_height="1284dp"
        android:layout_below="@+id/switcher"
        android:layout_centerHorizontal="true" >
    </RelativeLayout>

これRelativeLayoutで、レイアウトに合わせて幅と高さを調整できます。

次のステップはReaderViewこれRelativeLayoutにあなたを追加することです。動的に生成しているので、に追加する必要がありますonCreate()

     RelativeLayout layout = new RelativeLayout(this);

     RelativeLayout docViewLayout = (RelativeLayout) mButtonsView.findViewById(R.id.docViewLayout);
     docViewLayout.addView(mDocView);

     layout.addView(cramperView);

     setContentView(layout);

お役に立てれば。

于 2013-05-04T09:36:55.920 に答える