gpt4 book ai didi

java - 如何使用图像和滚动创建警报对话框 [ANDROID]

转载 作者:行者123 更新时间:2023-11-29 05:26:02 24 4
gpt4 key购买 nike

对话框 Java 代码:

final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Title...");
ScrollView scroll = new ScrollView(context);
scroll.setBackgroundColor(android.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Android custom dialog example!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.icon);
dialog.show();

此处的 XML 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:scrollbarAlwaysDrawVerticalTrack="true">
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>

我知道,如果我在警报对话框中只有文本,它会自动滚动,但是使用 imageview 自动滚动是行不通的。我该如何解决这个问题?

最佳答案

将您的布局放在 ScrollView 中:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
android:id="@+id/layout_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:scrollbarAlwaysDrawVerticalTrack="true" >

<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp" />

<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF" />

</LinearLayout>

<ScrollView>

我看到您的LinearLayout 有一个水平 方向。因此,如果是这种情况并且您想水平滚动,则应将 ScrollView 替换为 Horizo​​ntalScrollView 并将方向设置为水平。
让我知道这是否有效。

关于java - 如何使用图像和滚动创建警报对话框 [ANDROID],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22642684/

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