縦、横方向にスクロール可能なTableLayoutにピンチイン、ピンチアウト機能を実装しているのですが、
ピンチインをした後もスクロール領域がピンチイン前と変わっていないため、表示できない部分ができてしまいます。
JavaコードからScrollViewのスクロール領域を大きくする方法があればご教授頂きたく存じます。
以下、現状のソースです。
MainActivity
package com.example.expansion; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.ScrollView; import android.widget.TableRow; import android.widget.TextView; public class MainActivity extends AppCompatActivity { //private ImageView iView; //private Button button; private float scale = 1f; private ScaleGestureDetector detector; RelativeLayout base; ViewGroup w_view_group; ScrollView scrollView; LinearLayout linearLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); detector = new ScaleGestureDetector(this,new ScaleListener()); String[][] array = new String[10][2]; // ヘッダーにセットする String[] w_header_array = "勇気,元気,パワー,気合,強い,弱い,凄い".split(","); w_view_group = (ViewGroup) findViewById(R.id.search_table); scrollView = (ScrollView)findViewById(R.id.scrollView); linearLayout = (LinearLayout)findViewById(R.id.linearLayout); //行追加 getLayoutInflater().inflate(R.layout.layout_table, w_view_group); TableRow w_table_row = (TableRow) w_view_group.getChildAt(0); //一番上の段だけ文字を設定。ピンチインしたときにこの部分までスライドできず隠れてしまう。 for (int i = 0; i < w_header_array.length; i++) { ((TextView) (w_table_row.getChildAt(i))).setText(w_header_array[i]); } for (int i = 0; i < 10; i++) { getLayoutInflater().inflate(R.layout.layout_table, w_view_group); } scrollView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); } public boolean onTouchEvent(MotionEvent event) { detector.onTouchEvent(event); return super.onTouchEvent(event); } private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { @Override public boolean onScale(ScaleGestureDetector detector) { scale *= detector.getScaleFactor(); linearLayout.setScaleX(scale); linearLayout.setScaleY(scale); return true; } } }
activity_main
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/base" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.expansion.MainActivity"> <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="match_parent"> <HorizontalScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/linearLayout"> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/search_table" android:layout_width="match_parent" android:layout_height="match_parent"> </TableLayout> </LinearLayout> </HorizontalScrollView> </ScrollView> </RelativeLayout>
あなたの回答
tips
プレビュー