2016-11-27 1 views
0

だから私は「match_parent」にlayout_widthセットを持っているのLinearLayoutは、のは、次に、その内のHorizo​​ntalScrollViewがありますHorizo​​ntalScrollViewの子の子を画面の幅にするにはどうすればよいですか?

、のはB.

はその後RelativeLayoutは、内があることを呼ぶことにしましょうというA.を呼びましょう持っています1つの直接の子intをスクロール表示できるルールのために使用しています。

次に、Aと同じ幅にする複数のRelativeLayoutsがありますその他。私がこれをどのように達成できるかを教えてください!ユーティリティメソッドの下に使用して、画面の

<LinearLayout 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:orientation="vertical" > 


<HorizontalScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:fillViewport="true" 
    android:layout_weight="9"> 

    // Used because ScrollView can have only 1 child. 
    <RelativeLayout 
     android:id="@+id/directChild" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent"> 

     // This is the RelativeLayout that I want to fill the screen width with. 
     <RelativeLayout 
      android:id="@+id/howToMakeScreenWidth" 
      android:layout_width="385dp" 
      android:layout_height="match_parent"> 

答えて

0

検索幅:ここ

はXMLコードです。

Display display = getWindowManager().getDefaultDisplay(); 
Point size = new Point(); 
display.getSize(size); 
int width = size.x; 

最初RelativeLayoutがmatch_parentに変更された場合、それは限りの縁部を超えて広がっHorizo​​ntalScrollView、などとなりますので、その後、RelativeLayout

あなたの子供に動作しません
RelativeLayout.LayoutParams relParams = new RelativeLayout.LayoutParams(
       width, ViewGroup.LayoutParams.WRAP_CONTENT); 
yourRelativeLayout.setLayoutParams(relParams); 
+0

をその幅を割り当てますスクリーン。 –

+0

スクロールビューには右にスクロールする機能があるため、ScrollViewのスクロール可能な距離の長さにRelativeLayoutストレッチを行います。次のようになります。http://pasteboard.co/2STAt2Seg.png –

+0

答えが更新されました。 – Rahul

関連する問題