2016-09-05 10 views
-4

私は、画面上にEditTextButtton、下にはTextView、背後にはスペースを垂直に塗りつぶしたListViewというレイアウトを実現しようとしています。昨夜、アプリの処理をテストするために、ちょうどListViewの絶対的な高さを使用することを除いて、これは多かれ少なかれ正しいものでした。Android ListViewの高さに何が問題がありますか?

私は私で、多分魔法、私は、Androidのメーカーを閉じて、今それを開いてから、何が起こったかのGitリポジトリを持つかもしれないものまで、または多分無意識の変化を知りませんが、今ListViewを延長するようです無限下方ディスプレイオフ、この写真にオレンジ色の輪郭線によって強調とおり

enter image description here

Iは、様々なlayout_height値を試してみました、そしてそれは、上記PICため50dpです。 10dpのように低くても違いはなく、一番上の青色のアンカーライン上でマウスを使ってドラッグすると差はありません。

ここで何が間違っていますか、これを解決するにはどこを探してください。ここで

は、そのすべての壊れた栄光で、レイアウトのXMLです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    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:orientation="vertical" 
    android:layout_centerHorizontal="true" 
    tools:context="com.bradykelly.heavyweights.MainActivity" 
    android:weightSum="1"> 
<TextView 
     android:layout_width="match_parent" 
     android:layout_height="10dp" 
     android:text="@string/adjustment_label" 
     android:id="@+id/scale_text_view_label" 
     android:background="@color/colorPrimaryDark" 
     android:textColor="@color/textColorPrimary" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="20dp" 
     android:textAlignment="center" 
     android:gravity="center" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:layout_weight="0.09" 
     android:height="10dp"/> 
<EditText 
     android:id="@+id/editText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/text_view_border" 
     android:layout_marginTop="5dp" 
     android:ems="10" 
     android:inputType="text" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:enabled="true" 
     android:focusable="true"/> 
<Button 
     android:id="@+id/processButton" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="5dp" 
     android:text="@string/process_file_text" /> 
<ListView 
     android:cacheColorHint="#00000000" 
     android:scrollbars="none" 
     android:fadingEdge="vertical" 
     android:soundEffectsEnabled="true" 
     android:dividerHeight="1dp" 
     android:padding="5dp" 
     android:smoothScrollbar="true" 
     android:layout_weight="50" 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:drawSelectorOnTop="false" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginBottom="10dp" 
     android:layout_marginTop="5dp" 
     /> 
<TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView3" 
     android:background="@drawable/text_view_border" 
     android:layout_marginLeft="20dp" 
     android:textAlignment="center" 
     android:gravity="center" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:layout_marginRight="20dp" 
     android:layout_marginBottom="-20dp" 
     /> 
</LinearLayout> 
+0

'ListView'を' TextView'の下にしたいのですが、無限に下向きにしたくないのですか? – EdmDroid

+0

上記の画像の* xml *コードを投稿してください。 –

+0

質問を編集してレイアウトXMLを追加できますか? – JonasCz

答えて

2

私はlayout_weightプロパティを使用して、レイアウトにいくつかの変更を行いました。 Layoutxmlコードを適用してください。下記のlayoutを使用すると、screen shotに添付されているように、List viewの画面が表示されます。

List view height=50を指定し、weightと指定して問題が発生したためです。

You not need to define height when you are using weight property in your layout。私はListViewlayout_weightを使用しています

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:layout_centerHorizontal="true" 
    android:orientation="vertical" 
    android:weightSum="10"> 

    <TextView 
     android:id="@+id/scale_text_view_label" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="20dp" 
     android:layout_weight="1" 
     android:background="@color/colorPrimaryDark" 
     android:gravity="center" 
     android:text="Adjustment Label" 
     android:textAlignment="center" 
     android:textColor="#FFFFFF" 
     android:textSize="20sp" 
     android:textStyle="bold" /> 

    <EditText 
     android:id="@+id/editText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="5dp" 
     android:ems="10" 
     android:enabled="true" 
     android:focusable="true" 
     android:inputType="text" /> 

    <Button 
     android:id="@+id/processButton" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="5dp" 
     android:text="Process" /> 

    <ListView 
     android:id="@+id/ListView" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="5dp" 
     android:layout_weight="8" 
     android:cacheColorHint="#00000000" 
     android:dividerHeight="1dp" 
     android:drawSelectorOnTop="false" 
     android:fadingEdge="vertical" 
     android:padding="5dp" 
     android:scrollbars="none" 
     android:smoothScrollbar="true" 
     android:soundEffectsEnabled="true" /> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_marginBottom="-20dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="Testeing" 
     android:textAlignment="center" 
     android:textSize="20sp" 
     android:textStyle="bold" /> 
</LinearLayout> 

enter image description here

+1

この最も迅速で正確な答えをありがとうございます。 – ProfK

+0

@ProfKあなたを助けてくれてうれしいです:)。 –

0

。このことを確認します。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    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:orientation="vertical" 
    android:layout_centerHorizontal="true" 
    android:weightSum="1"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="test" 
     android:id="@+id/scale_text_view_label" 
     android:background="@color/colorPrimaryDark" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="20dp" 
     android:textAlignment="center" 
     android:gravity="center" 
     android:textSize="20sp" 
     android:textStyle="bold"/> 
    <EditText 
     android:id="@+id/editText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:ems="10" 
     android:inputType="text" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:enabled="true" 
     android:focusable="true"/> 
    <Button 
     android:id="@+id/processButton" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="5dp" 
     android:text="test" /> 
    <ListView 
     android:cacheColorHint="#00000000" 
     android:scrollbars="none" 
     android:fadingEdge="vertical" 
     android:soundEffectsEnabled="true" 
     android:dividerHeight="1dp" 
     android:padding="5dp" 
     android:smoothScrollbar="true" 
     android:layout_weight="1" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:drawSelectorOnTop="false" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginBottom="10dp" 
     android:layout_marginTop="5dp" 
     /> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView3" 
     android:layout_marginLeft="20dp" 
     android:textAlignment="center" 
     android:gravity="center" 
     android:text="Test" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:layout_marginRight="20dp" 
     /> 
</LinearLayout> 
+0

このレイアウトではリストビューが表示されません。 – ProfK

1

あなたは、リストビューのために

android:layout_weight="50" 

を使用しているが、重量合計が線形レイアウトでは1です。それがリストビューの問題です。この

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:weightSum="10"> 

<Textview 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"/> 

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"/> 

<Button 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"/> 

<ListView 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="6"/> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"/> 
</LinearLayout> 

重量回数などの

使用は、重量の合計と一致する必要があります。親レイアウトは塗りつぶしで、すべての子レイアウトに対して高さを0dpにする必要があります。

+0

私はすでに答えを受け入れていますが、重量と重量の合計についての情報をありがとう。 – ProfK

関連する問題