0

私はかなり跳ね返り、私がしようとしているものに合った解決策を見つけることができませんでした。
私はLinearLayout内に2つのRelativeLayoutsを持っています。
最初のRelativeLayoutが画面の60%を占めるようにしたいと思います。
2番目のレイアウトが画面の残りの部分を占めるようにしたいと思います。レイアウト、1つのViewGroupが高さの60%を占め、もう1つが残りの部分を埋める

私はウェイトを使用していますが、2番目のRelativeLayoutで2次ウェイトを使用しないようにする方法があるかどうかを確認しようとしています。
これは、ユーザーがボタンをクリックして最初のレイアウトを非表示にすることができるためです。

コードでは、最初のRelativeLayoutの可視性を「Gone」に設定することでこれを行います。
重さが.6と.4に設定され、合計が1に設定されている場合、最初のものが消され、2番目のものが正しく上がるが、40に設定されているために高さが上がらない%。

理想的には、画面上の残りのスペースを埋めるように設定することができます。したがって、最初のものが非表示になっていると、画面の100%がすべて使用されます。
2番目のビューの許容高さを増やすために最初のビューを非表示にすると、プログラムでより多くの処理を行う必要がありますか?
うまくいけば、これは意味があります。私に知らせていないなら、さらに明確にしようとします。

シンプルさといくつかのIDのために、RelativeLayoutsの内容のいくつかを取り除きました。

以下のコード:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:breadCrumbNavigationLayout="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/white" 
android:id="@+id/linearlayout1" 
android:focusable="true" 
android:focusableInTouchMode="true" 
android:weightSum="1"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:id="@+id/relativeLayout1" 
    android:layout_weight="0.6"> 
    <FrameLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/frame1" /> 
    <ProgressBar 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:id="@+id/progress" 
     android:indeterminateOnly="true" 
     android:keepScreenOn="true" 
     android:visibility="gone" /> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/relative2"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textSize="16dp" 
      android:gravity="center_horizontal" 
      android:layout_below="@+id/relativeLayout1" /> 
     <ListView 
      android:id="@+id/list" 
      android:minWidth="25px" 
      android:minHeight="25px" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:dividerHeight="1dp" /> 
    </RelativeLayout> 
</LinearLayout> 

答えて

0

あなたはこれを達成するには、Androidサポートライブラリの割合相対レイアウトを使用することができます。あなたのXMLファイルはなります

compile 'com.android.support:percent:24.2.1' 

そして、あなたのbuild.gradle(アプリケーションレベル)に次の行を追加して Percentage Relative Layout

輸入割合サポートライブラリ、

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:breadCrumbNavigationLayout="http://schemas.android.com/apk/res-auto" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" 
    android:id="@+id/linearlayout1" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:weightSum="1"> 

    <android.support.percent.PercentRelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<RelativeLayout 
android:layout_height="0dp" 
android:layout_width="match_parent" 
app:layout_heightPercent="60%" 
android:id="@+id/relativeLayout1" 
> 
<FrameLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/frame1" /> 
<ProgressBar 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:id="@+id/progress" 
    android:indeterminateOnly="true" 
    android:keepScreenOn="true" 
    android:visibility="gone" /> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/relativeLayout1" 
    android:id="@+id/relative2"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="" 
     android:textSize="16dp" 
     android:gravity="center_horizontal" 
     android:layout_below="@+id/relativeLayout1" /> 
    <ListView 
     android:id="@+id/list" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:dividerHeight="1dp" /> 
</RelativeLayout> 
</android.support.percent.PercentRelativeLayout> 

</LinearLayout> 

あなたが設定されたら、

relativeLayout1.setVisibility(View.GONE); 

あなたは、相対レイアウト2は、親空間全体を占有する。

私はそれがあなたを助けてくれることを願っています。ではごきげんよう。

+0

最初のレイアウトの高さを60%に、2番目のレイアウトを1番目のレイアウトの下に、2番目のレイアウトの高さをmatch_parentに設定できます。最初のレイアウトを隠すと、レイアウト全体を占有します。 –

+1

@Mike M. Okay。私は私の答えを編集します。ありがとう –

+0

私はこれを見ることができますが、それでも画面を閉じるために複数のパーセンテージが必要なように見えますか?コンテンツの1つにパーセンテージを設定し、残りの部分にもう1つのコンテンツを埋め込むことは可能ですか? – Kyle

関連する問題