2017-03-24 14 views
0

私はweightSumでLinearLayoutを使用しているので、全画面サイズで実行するジェネリック画面を設計できます。たぶん私はwrap_contentとmatch_parent属性を正しく理解できませんでした。 xmlファイルのコード全体を投稿すると、このエラーが表示されます。「あなたの投稿は主にコードであるようですが、詳細を追加してください。それは私がエラーを停止するためにこれらの余分な行を書いている理由です。LinearLayoutを使用した画像とボタンの高さが同じですか?

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/content_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      tools:context="com.hbss.hybridsoftwaresolutions.rashidfaheem.mysecondapplication.easypercentagecalculator.MainActivity" 
    tools:showIn="@layout/activity_main" 
    android:orientation="vertical" 
    android:weightSum="10" 
    android:background="#0d001c" 
    > 

    <View 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

    </View> 

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:weightSum="5" 
    > 
<ImageView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:src="@drawable/image01" 

    /> 
    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="Percent Calculator" 
     android:textSize="15dp" 
     android:layout_weight="3" 
     android:id="@+id/btnPCalculator" 
     /> 
    <View 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

    </View> 


</LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:weightSum="5" 
     > 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/image04" 

      /> 
     <Button 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="Percent Increase" 
      android:textSize="15dp" 
      android:layout_weight="3" 
      android:id="@+id/btnPIncrease" 
      /> 
     <View 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 

     </View> 


</LinearLayout> 







    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:weightSum="5" 
     > 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/image05" 

      /> 
     <Button 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="Percent Decrease" 
      android:textSize="15dp" 
      android:layout_weight="3" 
      android:id="@+id/btnPDecrease" 
      /> 
     <View 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 

     </View> 
</LinearLayout> 








    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:weightSum="5" 
     > 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/image02" 

      /> 
     <Button 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="Tip Calculator" 
      android:textSize="15dp" 
      android:layout_weight="3" 
      android:id="@+id/btnTCalculator" 
      /> 
     <View 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 

     </View> 
</LinearLayout> 






     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:weightSum="5" 
      > 
      <ImageView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:src="@drawable/image03" 

       /> 
      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:text="Percent Margin" 
       android:textSize="15dp" 
       android:layout_weight="3" 
       android:id="@+id/btnPMargin" 
       /> 
      <View 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"> 

      </View> 

    </LinearLayout> 





    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:weightSum="5" 
     > 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/image06" 

      /> 
     <Button 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="Percentage Change" 
      android:textSize="15dp" 
      android:layout_weight="3" 
      android:id="@+id/btnPChange" 
      /> 
     <View 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 

     </View> 
     </LinearLayout> 




    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:weightSum="5" 
     > 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/image07" 

      /> 
     <Button 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="Percentage (what % of)" 
      android:textSize="15dp" 
      android:layout_weight="3" 
      android:id="@+id/btnPWhatof" 
      /> 
     <View 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 

     </View> 
    </LinearLayout> 

    </LinearLayout> 

答えて

0

問題は、あなたのImageViewのとボタンの高さかもしれません。 wrap_contentの代わりにmatch_parentするためにそれらを設定するようにしてください:

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:weightSum="5"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:src="@drawable/image01"/> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:text="Percent Calculator" 
     android:textSize="15dp" 
     android:layout_weight="3" 
     android:id="@+id/btnPCalculator"/> 
    <View 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 

あなたは両方のTextViewとButtonの高さは、あなたのLinearLayout内で利用可能なすべてのスペースを埋めるようにmatch_parentを使用する必要があります。 wrap_contentを使用すると、利用可能なスペースの残りの部分を無視して必要なスペースのみを使用します。

+0

画像とボタンにmatch_parentを使用すると、画面全体が占有されます。実際に私は2つの線形レイアウトを使用しています。最初にブロック(画像+ボタン)の7行を垂直に塗りつぶし、ブロック(画像+ボタン)の各行の垂直レイアウトに画像+ボタン+空白(View)を調整する独自の水平線形レイアウトが表示されます重量。 –

+0

私は参照してください。あなたは私にXMLファイル全体を表示できますか? – Rob

+0

私は自分の投稿を編集し、全体のXMLコードを貼り付けました。同じ高さの画像とボタンを作るにはどうすればよいですか? –

関連する問題