我想为 AlertDialog 添加一个垂直滚动条,因为我的文本太长而无法在 1 个屏幕上显示:
I would like to add a vertical scrollbar to an AlertDialog because my text is too long to display on 1 screen:
我试过用:
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
但滚动条甚至不显示?
这是我正在使用的 xml 布局文件:
Here's the xml layout file I'm using:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:id="@+id/instructions_view" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A LONG TEXT 1"/>
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A LONG TEXT 2"/>
</LinearLayout>
我用 :
public void onClick(View v) {
switch(v.getId()){
case R.id.Button_Instructions:
InstructionsDialog();
break;
case R.id.Button_Exit:
ExitDialog();
break;
}
}
public void InstructionsDialog(){
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setIcon(R.drawable.icon);
ad.setTitle("Instructions ...");
ad.setView(LayoutInflater.from(this).inflate(R.layout.instructions_dialog,null));
ad.setPositiveButton("OK",
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
// OK, go back to Main menu
}
}
);
ad.setOnCancelListener(new DialogInterface.OnCancelListener(){
public void onCancel(DialogInterface dialog) {
// OK, go back to Main menu
}}
);
ad.show();
}
我现在找到了答案 => 现在可以使用了:
I found the answer now=> IT WORKS NOW WITH THIS :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:id="@+id/instructions_view" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A LONG TEXT 1"/>
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A LONG TEXT 2"/>
</LinearLayout>
</ScrollView>
为了让视图可滚动,它必须嵌套在 ScrollView 容器内:
In order for a view to scrollable, it must be nested inside of a ScrollView container:
<ScrollView>
<LinearLayout android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<TextView />
<Button />
</LinearLayout>
</ScrollView>
请注意,ScrollView 容器只能有一个子布局视图.例如,不能在没有 LinearLayout 的情况下将 TextView 和 Button 放置在 ScrollView 中.
Note that a ScrollView container can only have one child layout view. It is not possible, for example, to place a TextView and Button in a ScrollView without the LinearLayout.
这篇关于向Android中的AlertDialog添加垂直滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 GPS 获取用户的当前位置Get user#39;s current location using GPS(使用 GPS 获取用户的当前位置)
requestLocationUpdate() 抛出的 IllegalArgumentExceptionIllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 抛出的 IllegalArgumentException)
LocationManager 的 getLastKnownLocation 有多可靠,多久更How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新
如何检测位置提供者?GPS 或网络提供商How to detect Location Provider ? GPS or Network Provider(如何检测位置提供者?GPS 或网络提供商)
在应用启动期间获取当前位置Get current location during app launch(在应用启动期间获取当前位置)
locationManager.getLastKnownLocation() 返回 nulllocationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)