我在ScrollView和HorizontalScrollView中的自定义键盘视图有问题。特别是我的键盘没有显示,但正常显示其他组件作为一些文本视图。我的布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/miolayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/back_lavagna"
android:fillViewport="true"
android:orientation="vertical"
android:textAlignment="center" >
<HorizontalScrollView
android:id="@+id/miolayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/miolayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:ems="10" >
<requestFocus />
</EditText>
<android.inputmethodservice.KeyboardView
android:id="@+id/keyboardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#aabbcc"
android:focusable="false"
android:focusableInTouchMode="true"
android:visibility="visible" />
<TextView
android:id="@+id/risultato1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="risultato1"
android:textColor="#456"
android:textSize="20sp" />
<TextView
android:id="@+id/risultato2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="risultato1"
android:textColor="#076"
android:textSize="22sp" />
<TextView
android:id="@+id/risultato3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="risultato1"
android:textColor="#219"
android:textSize="24sp" />
<TextView
android:id="@+id/risultato4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="risultato1"
android:textColor="#006"
android:textSize="28sp" />
<TextView
android:id="@+id/risultato5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="risultato1 adsfdsg bdsfsd sdgfsd dsfgsd sdgfsf dsaffds"
android:textColor="#400"
android:textSize="30sp" />
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
如果我删除HorizontalScrollView似乎没问题,我的自定义键盘就会显示出来。 这是我班上的onCreate方法:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_keyboard_main);
keyboardView = (KeyboardView) findViewById(R.id.keyboardView);
Typeface type = Typeface.createFromAsset(getAssets(),
"fonts/DS-DIGI.TTF");
keyboard = new Keyboard(this, R.xml.keyboard_querty);
keyboardView.setKeyboard(keyboard);
keyboardView.setEnabled(true);
keyboardView.setPreviewEnabled(true);
keyboardView.setOnKeyListener((android.view.View.OnKeyListener) this);
keyboardView.setOnKeyboardActionListener(this);
keyCodeMap = new HashMap<String, String>();
keyCodeMap.put("1", "1");
keyCodeMap.put("2", "2");
keyCodeMap.put("3", "3");
keyCodeMap.put("4", "+");
keyCodeMap.put("5", "4");
keyCodeMap.put("6", "5");
keyCodeMap.put("7", "6");
keyCodeMap.put("8", "-");
keyCodeMap.put("9", "7");
keyCodeMap.put("10", "8");
keyCodeMap.put("11", "9");
keyCodeMap.put("12", "I");
keyCodeMap.put("13", "x");
keyCodeMap.put("14", "0");
keyCodeMap.put("15", "t");
keyCodeMap.put("16", ".");
currentEditText = (EditText) findViewById(R.id.editText1);
currentEditText.setTypeface(type);
currentEditText.setText(Html.fromHtml(" P(X)="));
currentEditText.setCursorVisible(false);
currentEditText.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
toggleKeyboardVisibility(currentEditText);
}
});
}
怎么了? 我需要一个能够水平和垂直滚动的布局,因为动态方式的组件可能会大于屏幕的大小。
先谢谢