2016-08-29 5 views
0

https://github.com/bmelnychuk/AndroidTreeViewを使用してツリーベースのメニューを表示しています。私は確かに非常に基本的なものを逃していると私は私の間違いを確認する別の目が必要です。ライブラリによれば、ビューを動的に作成し(基本的にはスクロールビュー)、子としてRelativeLayoutに追加します。以下は私のレイアウトXMLRelativeLayoutに子ビューを追加できません

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

    <Button 
     android:id="@+id/reload_menu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="re load menu" /> 

    <RelativeLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/reload_menu"></RelativeLayout> 

</RelativeLayout> 

であり、ここで私が表示されている。このRelativeLayoutに

AndroidTreeView tView = new AndroidTreeView(getApplicationContext(), root); 

    RelativeLayout container = (RelativeLayout) findViewById(R.id.container); 
    container.addView(tView.getView()); 

のコード行は、例外なしに実行していても

、私はツリービューが表示されていないが、私のルートを追加してい方法です。私もtView.getView()をチェックし、それは完璧に見える。スクロールビューです。ある人が私を助けてくれますか?

答えて

2

ビューに子ビューが1つしかない場合は、RelativeLayoutを使用する必要はありません。代わりにFrameLayoutを使用してください。私はmatch_parentにlayout_height変更

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

<Button 
    android:id="@+id/reload_menu" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="re load menu" /> 

<FrameLayout 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@id/reload_menu"></FrameLayout> 

</RelativeLayout> 

あなたのボタンがでframeLayoutその後は上記の設定の追加属性android:layout_below="@id/reload_menu"する必要があります場合は、それもmatch_parent属性で動作します。あなたの主な問題は、のlayout_heightにmatch_contentがあると思っていました。スクロールビューはそれに合わせていくらかの高さを持っている必要があるからです。私の問題を指摘して時間を割いて

AndroidTreeView tView = new AndroidTreeView(this, root); //this is Activity 
+0

ありがとう:

は、現在のコンテキスト(アクティビティコード)を使用しても試してみてください。もう少し理解したいと思います。高さをmatch_parentに変更しました。コードでは、子の高さと幅(この場合はtView)を設定しようとしています。 AndroidTreeViewはライブラリの一部であるため、私が使用できるsetLayoutParamsの実装はありません。子を追加した後にレイアウトを更新するために使用できる他のアイデアはありますか? –

+0

もし動作していないのであれば、コードがアクティビティにある場合はgetApplicationContext()をこれに変更してみてください。 –

関連する問題