2016-07-25 5 views
0

内部の重量とのLinearLayout私はScrollViewでこのイライラ問題を抱えているが、ここに私の階層です:アンドロイド:ScrollView

ScrollView (Vertical) 
    LinearLayout (Vertical) 
     ImageView weight= 0.5 
     Whatever weight= 0.1 
     Whatever weight= 0.2 
     Whatever weight= 0.2 

私はScrollViewを削除(メインアイテムとしてのLinearLayoutを聞かせて)場合は、この任意の画像で正常に動作します。画像は画面サイズの50%を占め、残りの画像は残りの画像を占めます。

ただし、ScrollViewがここにある場合、画像が大きすぎると「重み」パラメータは完全に無視されます。画像は画面幅に合わせて何かを行いますが、明らかに背が高くなり、画面の50%以上です。編集:実際には、すべて "重量" 属性は無視されているように見える:

ScrollViewなし:ScrollView付き enter image description here

enter image description here

私はリニアレイアウトがスクロールすることなく、完璧にフィットします。それは可能ですか?私は画像オプション(scaleType、adjustViewBounds)のいくつかを変更しようとしましたが、私が望むものを持つことはできませんでした。

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true"> 

<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="1"> 


    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" 
     android:adjustViewBounds="true" 
     android:src="@drawable/testing" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.2" 
     android:text="I'M A TEST" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:text="I'M A TEST" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.2" 
     android:text="I'M A TEST" /> 

</LinearLayout> 
</ScrollView> 

注:ここでは

は全体のxmlだ、私はこのようにPullToRefresh ScrollView

+3

好奇心から外れています。スクロールしたくない場合は、なぜスクロールビューが必要ですか? – wanpanman

+1

基本的には^。スクロールビューには次元がありません。無限にすることができます。あなたのイメージビューが何を期待しているのですか?それが線形レイアウトの場合、それは分かります。 ScrollViewは、必要なだけのスペースを占有します。 – Vucko

+1

これは正しくないようです。 https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.htmlをご覧ください。必要なものかもしれません。 – tynn

答えて

1

私は親リニアレイアウト(メインrelativeLayout)を追加することによってそれを解決:

ScrollView (Vertical) 
     LineaLayout 
      LinearLayout (Vertical) 
       ImageView weight= 0.5 
       Whatever weight= 0.1 
       Whatever weight= 0.2 
       Whatever weight= 0.2 

そしてchildLinearLayout.getLayoutParams().height

-1

てみてくださいを使用しているので、私はScrollViewを必要としています。

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

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

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:adjustViewBounds="true" 
     android:padding="50dp" 
     android:src="@drawable/ic_launcher" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:padding="20dp" 
     android:text="I&apos;M A TEST" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:padding="20dp" 
     android:text="I&apos;M A TEST" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:padding="10dp" 
     android:text="I&apos;M A TEST" /> 
</LinearLayout> 
</ScrollView> 
+0

しかし、これは50%、20%、20%、10%の高さの要件を尊重しません。 –

+0

@Rotwang変更コードがありますのでご確認ください –

+0

上記と同じ... –

0
で画面の高さに、プログラムの子のLinearLayoutの高さを設定

多すぎるかもしれませんが、android:fillViewport="true"ScrollViewに追加すると、問題が解決する可能性があります。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" >