Android的滚动视图垂直滚动条显示不出来 [英] android scrollview vertical scrollbar not showing up
问题描述
所以,我有以下布局自定义AlertDialog
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / popuplayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_gravity =center_vertical
机器人:fillViewport =真
机器人:方向=垂直> <的TextView
机器人:ID =@ + ID / popup_date
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginBottom =5dip
机器人:比重=中心
机器人:文字=日期时间
机器人:文字颜色=#CCCCCC
机器人:TEXTSIZE =14sp/> <查看
机器人:layout_width =match_parent
机器人:layout_height =1dip
机器人:背景=#333333/> <滚动型
机器人:ID =@ + ID / popup_scrollview
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:fillViewport =真
机器人:方向=垂直
机器人:填充=10dp> <的TextView
机器人:ID =@ + ID / popup_text
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:重力=CENTER_HORIZONTAL
机器人:文字=消息文本
机器人:文字颜色=#FFCC00
机器人:TEXTSIZE =18sp/>
< /滚动型> <按钮
机器人:ID =@ + ID / btnSpam
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
安卓的onClick =markSpam
机器人:填充=10dp
机器人:文字=标记为垃圾邮件/>< / LinearLayout中>
在这里是怎么了显示它:
getWindow()requestFeature(Window.FEATURE_NO_TITLE)。
getWindow()setBackgroundDrawable(新ColorDrawable(0))。LayoutInflater layoutInflater = LayoutInflater.from(上下文);查看promptView = layoutInflater.inflate(
R.layout.activity_show_notification,NULL);AlertDialog.Builder alertDialogBuilder =新AlertDialog.Builder(
背景);alertDialogBuilder.setView(promptView);//创建一个警告对话框
AlertDialog弹出= alertDialogBuilder.create();popup.setTitle(职称);
popup.setMessage();
popup.show();TextView的MessageText中=(TextView中)popup.findViewById(android.R.id.message);
messageText.setPadding(0,0,0,0);
messageText.setHeight(0);
messageText.setVisibility(View.INVISIBLE);TextView的popupDate =(TextView中)popup.findViewById(R.id.popup_date);
TextView的popupText =(TextView中)popup.findViewById(R.id.popup_text);
popupDate.setText(mdate);
popupText.setText(消息);popupText.setMovementMethod(新ScrollingMovementMethod());
然而,当有较长的文本,它被切割和垂直滚动条显示不出来:(
谁能帮什么,我在这里丢失?您的帮助将大大AP preciated。谢谢
更新
下面是一个使用全息主题为对话框中的应用程序的XML文件的活动:
<活动
机器人:名字=com.domain.notifier.ShowNotification
机器人:标签=@字符串/ title_activity_show_notification
机器人:noHistory =真
机器人:主题=@安卓风格/ Theme.Holo.Dialog>
< /活性GT;
和styles.xml文件:
<资源> <! -
基础应用的主题,依赖于API级别。这个主题被替换
通过AppBaseTheme从RES /值-VXX /较新设备上styles.xml。
- >
<样式名称=AppBaseTheme父=机器人:Theme.Light>
<! -
在新API的级别可以去提供自定义主题
RES /值-VXX / styles.xml,而自定义相关
向后兼容性可以去这里。
- >
< /风格> <! - 应用的主题。 - >
<样式名称=AppTheme父=AppBaseTheme>
<! - 所有自定义不特定于一个特定的API级别的可以去这里。 - >
< /风格>< /资源>
这是怎么开始的警告对话框活动:
意图intnt =新意图(背景下,ShowNotification.class);
intnt.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intnt.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intnt.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);intnt.putExtra(地址,地址);
intnt.putExtra(身体,身体);
intnt.putExtra(日,日期);
context.startActivity(intnt);
我试图重现您的问题,它的一些修改之后的作品。基本上我从promptView所做的视图查询。
getWindow()setBackgroundDrawable(新ColorDrawable(0))。 LayoutInflater layoutInflater = LayoutInflater.from(本); 查看promptView = layoutInflater.inflate(
R.layout.test,NULL); AlertDialog.Builder alertDialogBuilder =新AlertDialog.Builder(
这个); alertDialogBuilder.setView(promptView); //创建一个警告对话框
AlertDialog弹出= alertDialogBuilder.create();
popup.setTitle(称号); TextView的MessageText中=(TextView中)promptView.findViewById(android.R.id.message);
TextView的popupDate =(TextView中)promptView.findViewById(R.id.popup_date);
TextView的popupText =(TextView中)promptView.findViewById(R.id.popup_text); popupDate.setText(DATE);
popupText.setText(longTestString);
popup.show();
更新:
我忽视的是,在我的解决方案滚动视图推出底部的按钮。
如果您在滚动视图中添加布局体重正常工作。这比需要的所有可用空间,如有必要显示吧。
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / popuplayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_gravity =center_vertical
机器人:fillViewport =真
机器人:方向=垂直><的TextView
机器人:ID =@ + ID / popup_date
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginBottom =5dip
机器人:比重=中心
机器人:文字=日期时间
机器人:文字颜色=#CCCCCC
机器人:TEXTSIZE =14sp/><查看
机器人:layout_width =match_parent
机器人:layout_height =1dip
机器人:背景=#333333/><滚动型
机器人:ID =@ + ID / popup_scrollview
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:fillViewport =真
机器人:方向=垂直
机器人:填充=10dp
机器人:layout_weight =0.5> <的TextView
机器人:ID =@ + ID / popup_text
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:重力=CENTER_HORIZONTAL
机器人:文字=消息文本
机器人:文字颜色=#FFCC00
机器人:TEXTSIZE =18sp/>
< /滚动型><按钮
机器人:ID =@ + ID / btnSpam
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
安卓的onClick =markSpam
机器人:填充=10dp
机器人:文字=标记为垃圾邮件/>
So I have below layout for custom AlertDialog:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popuplayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:fillViewport="true"
android:orientation="vertical" >
<TextView
android:id="@+id/popup_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:gravity="center"
android:text="DateTime"
android:textColor="#cccccc"
android:textSize="14sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#333333" />
<ScrollView
android:id="@+id/popup_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="@+id/popup_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Message Text"
android:textColor="#FFCC00"
android:textSize="18sp" />
</ScrollView>
<Button
android:id="@+id/btnSpam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="markSpam"
android:padding="10dp"
android:text="Mark as Spam" />
</LinearLayout>
and here is how I am showing it:
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawable(new ColorDrawable(0));
LayoutInflater layoutInflater = LayoutInflater.from(context);
View promptView = layoutInflater.inflate(
R.layout.activity_show_notification, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
alertDialogBuilder.setView(promptView);
// create an alert dialog
AlertDialog popup = alertDialogBuilder.create();
popup.setTitle(title);
popup.setMessage("");
popup.show();
TextView messageText = (TextView) popup.findViewById(android.R.id.message);
messageText.setPadding(0, 0, 0, 0);
messageText.setHeight(0);
messageText.setVisibility(View.INVISIBLE);
TextView popupDate = (TextView) popup.findViewById(R.id.popup_date);
TextView popupText = (TextView) popup.findViewById(R.id.popup_text);
popupDate.setText(mdate);
popupText.setText(message);
popupText.setMovementMethod(new ScrollingMovementMethod());
However when there is longer text, it is cut and vertical scrollbar doesn't show up :(
Can anyone help what I am missing here ? Your help will be greatly appreciated. Thanks
Update
Here is activity in app xml file using holo theme for the dialog:
<activity
android:name="com.domain.notifier.ShowNotification"
android:label="@string/title_activity_show_notification"
android:noHistory="true"
android:theme="@android:style/Theme.Holo.Dialog" >
</activity>
And styles.xml file:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
This is how I start alert dialog activity:
Intent intnt = new Intent(context, ShowNotification.class);
intnt.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intnt.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intnt.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intnt.putExtra("address", address);
intnt.putExtra("body", body);
intnt.putExtra("date", date);
context.startActivity(intnt);
I've tried to reproduce your issue and it works after some modifications. Basically I made the view lookup from the promptView.
getWindow().setBackgroundDrawable(new ColorDrawable(0));
LayoutInflater layoutInflater = LayoutInflater.from(this);
View promptView = layoutInflater.inflate(
R.layout.test, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
this);
alertDialogBuilder.setView(promptView);
// create an alert dialog
AlertDialog popup = alertDialogBuilder.create();
popup.setTitle("title");
TextView messageText = (TextView) promptView.findViewById(android.R.id.message);
TextView popupDate = (TextView) promptView.findViewById(R.id.popup_date);
TextView popupText = (TextView) promptView.findViewById(R.id.popup_text);
popupDate.setText("date");
popupText.setText(longTestString);
popup.show();
UPDATE:
I've overlooked that in my solution the scrollview pushes out the button on the bottom. It works fine if you add a layout-weight in your Scrollview. It than takes all available space and displays the bars if necessary.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popuplayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:fillViewport="true"
android:orientation="vertical" >
<TextView
android:id="@+id/popup_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:gravity="center"
android:text="DateTime"
android:textColor="#cccccc"
android:textSize="14sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#333333" />
<ScrollView
android:id="@+id/popup_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical"
android:padding="10dp"
android:layout_weight="0.5">
<TextView
android:id="@+id/popup_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Message Text"
android:textColor="#FFCC00"
android:textSize="18sp" />
</ScrollView>
<Button
android:id="@+id/btnSpam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="markSpam"
android:padding="10dp"
android:text="Mark as Spam" />
这篇关于Android的滚动视图垂直滚动条显示不出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!