2012-02-19 13 views
1

電卓のための簡単なインターフェイスを設計したいと思います。計算機には2つのキーグループ、基本キーと余分なキーがあります。余分な鍵をHorizontalScrollViewに入れたい。ここではXMLファイルです:しかし、それは非常にうまく機能し、私は水平方向にスクロールし、私が望む任意のボタンをクリックすることができHorizo​​ntalScrollView内のボタンをカスタマイズする

​​

<HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="A" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="B" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="C" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="D" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="E" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="F" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="G" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="H" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="I" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="J" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="K" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="L" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="M" /> 
     </LinearLayout> 
    </HorizontalScrollView> 

は、ここでそれがどのように見えるかです。しかし私はそれをよりカスタマイズしたいと思う。したがって、私の質問は次のとおりです。

  • 各ボタンの幅を編集して、一度に5つのボタンしか画面に表示できないようにするにはどうすればよいですか。
  • 5つのボタンのオフセットでスクロールするにはどうすればいいですか?つまり、左端に5つのボタンが表示され、右にスクロールすると、5つのボタンが左に移動し、次の5つのボタンが表示されます。
  • スクロールバーを消す方法(つまり、目に見えないスクロールバーでスクロールする)

いただきありがとうございます:)

答えて

2

をあなたのLinearLayoutにandroid:weightsum="5"を追加し、各ボタンにandroid:layout_weight="1"を追加する場合、私はそれが一度に画面上でそれらの5を置くと思い。しかし、私は体重属性を使用するのはあまりよくありません。いつでも私はそれを使用して、推測とチェックの束になります。しかし、私の腸は、あなたが何とか体重と体重で何をしているかを達成することができます。

しかし、私はあなたがどんなスクリーンにいても常に5つのボタンを表示するのが理にかなっているのだろうか?私にとっては、画面の最小のものが4つのボタンを取得し、画面の幅が最大のものが6つあるかもしれないように、少なくともいくつかは変えたいと思うように思えます。そうしないと、非常に広い範囲のボタンサイズさまざまなデバイス密度のすべてにわたって

は、あなたのHorizo​​ntalScrollViewにこれを追加します。あなたのためのスクロールバーの世話をする必要があります

android:scrollbars="false" 

を。

一度に5つずつスクロールする部分については、horizontalScrollView.smoothScrollBy()メソッドで手動で処理する必要があるかもしれませんが、計算にはどのくらい必要かを判断する必要があります5つのボタンを渡すために行く。その後、あなたのonTouchリスナーを無効にして、smoothScrollBy()の呼び出しを行います。

smoothScrollBy() - smoothScrollTo()を調べる価値もあります。

関連する問題