0

このコードをxmlではなく、クラスJavaでAndroidにスクロールバーまたはスクロールビューを追加するにはどうすればよいですか?

LayoutInflater inflater = (LayoutInflater)   getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
view = inflater.inflate(R.layout.srvr, null);
layout = (RelativeLayout) view.findViewById(R.id.relativeLayout1);
RelativeLayout.LayoutParams labelLayoutParams = new  RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

layout.setLayoutParams(labelLayoutParams);

labelLayoutParams = new RelativeLayout.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    labelLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    labelLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    labelLayoutParams.leftMargin=120;

   final EditText tt = new EditText(this);
      tt.setTag(i);
      tt.setText(DisplayName_list[i].toString());
      tt.setMinWidth(230);
      tt.setMaxWidth(230);
      tt.setMaxLines(1);
4

3 に答える 3

1

私がよく理解しているように、プログラムで ScrollView を作成したいと考えています。他のビューと同じように作成します。

ScrollView sc = new ScrollView(this);
sc.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
sc.setFillViewport(true);

そして、それにビューを追加する必要があります。ScrollView に追加するビューがルート ビューであることを確認してください。

sc.addView(ROOT_VIEW)

あなたの場合、 ROOT_VIEW は RelativeLayout のレイアウトです

于 2012-10-14T02:05:07.903 に答える
0

これを親として含める

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

// ここに Layout タグを配置する必要があります

</ScrollView>
于 2014-12-29T20:07:40.247 に答える