我想一个垂直滚动条添加到AlertDialog,因为我的文字太长,显示1屏:
我曾尝试使用:
安卓滚动条=垂直
机器人:scrollbarAlwaysDrawVerticalTrack =真
但滚动条甚至不显示?
下面是我使用的XML布局文件:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:滚动条=垂直
机器人:scrollbarAlwaysDrawVerticalTrack =真
机器人:ID =@ + ID / instructions_view>
< TextView的机器人:ID =@ + ID / TextView01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=第1条:......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
>< / TextView的>
< TextView的机器人:ID =@ + ID / TextView02
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=第2节:...文本...文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
到底......到底......到底>!< / TextView的>
< / LinearLayout中>
我所说的AlertsDialog有:
公共无效的onClick(视图v){
开关(v.getId()){
案例R.id.Button_Instructions:
InstructionsDialog();
打破;
案例R.id.Button_Exit:
ExitDialog();
打破;
}
}
公共无效InstructionsDialog(){
AlertDialog.Builder广告=新AlertDialog.Builder(本);
ad.setIcon(R.drawable.icon);
ad.setTitle(指令......);
ad.setView(LayoutInflater.from(本).inflate(R.layout.instructions_dialog,NULL));
ad.setPositiveButton(OK,
新android.content.DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话,诠释ARG1){
// OK,回到主菜单
}
}
);
ad.setOnCancelListener(新DialogInterface.OnCancelListener(){
公共无效OnCancel的(DialogInterface对话){
// OK,回到主菜单
}}
);
ad.show();
}
我找到了答案,现在=>现在它工作这一点:
< XML版本=1.0编码=UTF-8&GT?;
<滚动型机器人:ID =@ + ID / ScrollView01
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
的xmlns:机器人=http://schemas.android.com/apk/res/android>
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:滚动条=垂直
机器人:scrollbarAlwaysDrawVerticalTrack =真
机器人:ID =@ + ID / instructions_view>
< TextView的机器人:ID =@ + ID / TextView01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=第1条:......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
>< / TextView的>
< TextView的机器人:ID =@ + ID / TextView02
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=第2节:...文本...文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
文字......文字......文字......文字......文字......文字......文字......文字......文字...文字...
到底......到底......到底>!< / TextView的>
< / LinearLayout中>
< /滚动型>
解决方案
为了使以滚动的,它必须被嵌套在滚动型
容器内:
<滚动型>
<的LinearLayout机器人:方向=垂直
机器人:滚动条=垂直
机器人:scrollbarAlwaysDrawVerticalTrack =真正的>
<的TextView />
<按钮/>
< / LinearLayout中>
< /滚动型>
请注意,滚动型
容器只能有一个孩子的布局图。这是不可能的,例如,把一个的TextView
和按钮
在滚动型
而不的LinearLayout
。
I would like to add a vertical scrollbar to an AlertDialog because my text is too long to display on 1 screen:
I have tried to use :
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
but the scrollbars don't even display ?
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="section 1 :...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
"></TextView>
<TextView android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="section2 :...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
end ... end ... end !"></TextView>
</LinearLayout>
I call the AlertsDialog with :
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 android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<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="section 1 :...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
"></TextView>
<TextView android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="section2 :...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
text...text...text...text...text...text...text...text...text...text...
end ... end ... end !"></TextView>
</LinearLayout>
</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>
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
.
相关推荐
最新文章