2017-02-09 6 views
-1

Androidで奇妙な問題が発生しています。 ListViewの下にLinearLayoutがあります。リストビューの幅は0dp、layout_weightは90です。線形レイアウトlayout_weightは10、高さは0dpです。デバイスでは線形レイアウトが消えます。Androidのレイアウトは、デザイナーで正しくありますが、デバイスに間違いがあります。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <ListView android:id="@+id/chatsListView" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="90" 
     android:divider="@null" 
     android:dividerHeight="0dp" 
     android:listSelector="@android:color/transparent" 
     android:transcriptMode="alwaysScroll" 
     /> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="10" 
     android:padding="10dp"> 
     <EditText 
      android:id="@+id/messageEditText" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:inputType="textMultiLine" 
      android:hint="type message here" 
      android:ems="10"/> 

     <ImageButton 
      android:id="@+id/sendMessageButton" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:background="@drawable/send_button"/> 

    </LinearLayout> 

</LinearLayout> 

私はそれが上記の問題であることを知る必要があります。私は別の方法でそれをしたくありません。私は論理的に学ぶためにこのプロジェクトをやっていて、ペーストをコピーしていません。デザイナーで

ここにプレビュー:

Here preview at designer

ここでのプレビューは、デバイスである:

Here is preview in device

私が開閉キーボードとき、それはデザイナーのようにサイズを変更します。コードにエラーがあるかどうかを知る必要があります。

編集:アンドロイド-devのIRCからZharfは、この解決策を見つけた:

Viewpager is being pushed out of the screen [CoordinatorLayout] [Design Library]

+0

** PercentRelativeLayout **を使用しただけであれば、余分な不要なLinearLayoutを取り除くことができます。 –

+0

外側の 'LinearLayout'に' android:weightSum = "100" 'を追加してみてください。 – Slav

+0

「デザイナー」と「実際の」デバイスのデバイスから詳細を提供できますか?デバイスのサイズやデバイスそのもの(ネクサス、サムスンなど)のようなものです。 – hehe

答えて

-1

はこれを試して...あなただけのparrentリニアレイアウトで1行weightsumを逃しました。 これを追加します。アンドロイドのlayout_weight = "1" instade:リストビューでlayout_weight = "90"

android:weightSum="100" 

ので、あなたの最終的なコードは

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:weightSum="100"> 

     <ListView android:id="@+id/chatsListView" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="90" 
     android:divider="@null" 
     android:dividerHeight="0dp" 
     android:listSelector="@android:color/transparent" 
     android:transcriptMode="alwaysScroll" 
     /> 

     <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="10" 
     android:padding="10dp"> 

     <EditText 
      android:id="@+id/messageEditText" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:inputType="textMultiLine" 
      android:hint="type message here" 
      android:ems="10"/> 

     <ImageButton 
      android:id="@+id/sendMessageButton" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:background="@drawable/send_button"/> 

    </LinearLayout> 

</LinearLayout> 
+1

私は重量を前もって設定したことを思い出して、これが問題だとは思わない。デザイナーでは、レイアウトは正しいです。 – Programmer01

+0

はそのスクリーンショットを提供しますか?ちょうどリンクを提供する –

+0

私は離れている、私が家に帰るとすぐに私は1つを提供します。私を助けてくれてありがとう。 – Programmer01

0

利用アンドロイドのように見えます。またandroid:android:layout_height = "wrap_content" instade:layout_height = "0dp" LinearLayoutでlayout_weightを使用しないでください。 EditTextではlayout_weight = "1"を使用できます。 これはあなたの問題を解決することを願っています:)

+1

ロジックはbehinbdはどこですか?私は、問題が論理的にどこにあるのかを知る必要があると言いました。 – Programmer01

+0

ListViewとLinearLayoutでlayout_weight = "90"&layout_weight = "10"を使用するので、デバイスの高さの90倍をリストビューに、デバイスの高さの10倍をLinearLayoutに分割します。そのため、さまざまなデバイスで異なる動作をします。 – Farya

+0

あなたは間違っていると思います。すべてのデバイスでこのルールを尊重する必要があります。 – Programmer01

関連する問題