2016-03-23 15 views
0

私のアプリの設計にはいくつかの困難があります。私の画面にはツールバーといくつかの編集フィールドが含まれているはずです。これらのフィールドは、ツールバーの下の画面の上部に配置する必要があります。最後に、この(画像の品質のために申し訳ありません)のようになります。このためレイアウトのハイゲースの第2四半期を取得

enter image description here

が、私は4つの部分に等しく、第二四半期に私の編集フィールドを提起するために画面の高さを破ることにしました。私はこれを達成するために次のコードを使用しようとしましたが、それは役に立たない:すべてのより小さい相対レイアウトがすべての画面を取る。 は私も試してみました:

  • "wrap_content" と "fill_parent" を置き換えるために、リニアレイアウト

  • と親の相対的なレイアウトを置換します。

これらの操作の後に、より小さいレイアウトは単に消えます。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 

    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:baselineAligned="false"  > 


    <include android:id = "@+id/toolbarLogo" layout="@layout/toolbar_logo"></include> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.25" 
     /> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.25" 
     > 

     <EditText 
      .../> 

     <EditText 
      ... 
      /> 

     <Button 
      .../>  

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.5" 
     /> 

</RelativeLayout> 

この問題をどうかお手伝いできますか?

答えて

0

ルートレイアウトをLinearLayoutに変更し、向きが垂直に設定されていることを確認します。例えば、以下の1.を参照してくださいコードであることを子供のlayout_widthを変更します。

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#f00"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#0f0"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#00f"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#f0f"/> 

</LinearLayout> 
0

はそれぞれのLinearLayoutのため

android:layout_weight="1" 

を設定し、 がため

android:weightSum="4" 

を設定し...それを試してみてください親LinearLayoutおよび

この例のように。

01あなたは、すべての画面で、彼らは同じように見えるし、もちろんそれはあるので、あなたが素晴らしいですprocentegeによって、あなたの意見の 高さマージンを設定することができ、この libraryとGoogleのライブラリ PercentRelativeLayoutを使用することができます
<?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"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="4"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#0ff"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#ff2"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#01a"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#101"/> 

</LinearLayout> 

</RelativeLayout> 
0

それをコード化することは難しくありません。ここでは例:

<android.support.percent.PercentRelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    <ImageView 
     app:layout_widthPercent="50%" 
     app:layout_heightPercent="50%" 
     app:layout_marginTopPercent="25%" 
     app:layout_marginLeftPercent="25%"/> 
</android.support.percent.PercentRelativeLayout> 

あなたのbuild.gradleにGoogleのhttps://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html

そして、あなたの場合は、おそらく次のようになりますためによって

dependencies { 
    compile 'com.android.support:percent:23.2.0' 
} 

公式ドキュメントを、この行を追加する必要があります

<RelativeLayout 
     android:id="@+id/firstLayout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     app:layout_heightPercent="10%" 
     /> 

    <LinearLayout 
     android:id="@+id/secondLayout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_below="@+id/firstLayout" 
     android:orientation="vertical" 
     app:layout_heightPercent="40%"> 

     <EditText 
      android:layout_width="200dp" 
      android:layout_height="60dp"/> 

     <EditText 
      android:layout_width="200dp" 
      android:layout_height="60dp"/> 

     <Button 
      android:layout_width="200dp" 
      android:layout_height="60dp"/> 

    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_below="@+id/secondLayout" 
     app:layout_heightPercent="30%" 

     /> 

</android.support.percent.PercentRelativeLayout> 

これが役に立ちます。

関連する問題