gpt4 book ai didi

android scrollview垂直滚动条不显示

转载 作者:行者123 更新时间:2023-11-29 17:50:18 24 4
gpt4 key购买 nike

所以我有以下自定义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>

下面是我展示它的方式:

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());

但是当文本较长时,它会被剪切并且垂直滚动条不会显示 :(

任何人都可以帮助我在这里缺少什么吗?对你的帮助表示感谢。谢谢

更新

这是在对话框中使用全息主题的应用程序 xml 文件中的 Activity :

 <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>

和styles.xml文件:

<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>

这就是我启动警报对话框 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);

最佳答案

我已尝试重现您的问题,经过一些修改后它可以正常工作。基本上我从 promptView 进行了 View 查找。

    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();

更新:

我忽略了在我的解决方案中 ScrollView 推出底部的按钮。如果您在 Scrollview 中添加布局粗细,效果会很好。它会占用所有可用空间并在必要时显示条形图。

<?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" />

enter image description here

关于android scrollview垂直滚动条不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23364163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com