在对话框中使用Scrollview时出现的问题 [英] Issue when using Scrollview inside Dialog
本文介绍了在对话框中使用Scrollview时出现的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在放大一个对话框中的布局,该对话框包含一个滚动视图,但是该布局没有滚动。我已经从stackoverflow提到了很多问题,但是后来也无法正常工作。我的layout.xml文件如下:
<?xml version = 1.0 encoding = utf-8?> ;
< ScrollView
xmlns:android = http://schemas.android.com/apk/res/android
android:layout_width = fill_parent
android:layout_height = match_parent
android:layout_margin = 5dp
android:background = @ color / White
>
< LinearLayout
android:layout_width = match_parent
android:layout_height = wrap_content
android:background = @ color / White
android:scrollbars = vertical
android:scrollbarAlwaysDrawVerticalTrack = true
android:orientation = vertical>
< TextView
android:layout_width = wrap_content
android:layout_height = wrap_content
android:layout_gravity = center_horizontal
android: layout_margin = 5dp
android:text =更新可用
android:textColor =#000000 />
< TextView
android:layout_width = match_parent
android:layout_height = wrap_content
android:layout_margin = 5dp
android:重力=中心
android:text = @ string / upgrade_msg
android:textColor =#000000 />
< ImageView
android:layout_width = wrap_content
android:layout_height = 300dp
android:layout_margin = 3dp
android: layout_weight = 0.02
android:src = @ drawable / updateimg2 />
<按钮
android:id = @ + id / btn_upgrade
android:layout_width = fill_parent
android:layout_height = wrap_content
android:layout_below = @ id / tv_forget_pwd
android:layout_marginLeft = 10dp
android:layout_marginRight = 10dp
android:layout_marginTop = 10dp
android :background = @ color / White
android:gravity = center
android:text =立即升级
android:textColor = @ color / Black />
< ImageView
android:id = @ + id / imageView1
android:layout_width = fill_parent
android:layout_height = wrap_content
android:layout_marginLeft = 10dp
android:layout_marginRight = 10dp
android:layout_marginTop = 10dp
android:scaleType = fitXY
android:src = @ drawable / line_y_h />
<按钮
android:id = @ + id / btn_remind
android:layout_width = fill_parent
android:layout_height = wrap_content
android:layout_below = @ id / tv_forget_pwd
android:layout_marginLeft = 10dp
android:layout_marginRight = 10dp
android:layout_marginTop = 10dp
android :background = @ color / White
android:gravity = center
android:text =稍后提醒我
android:textColor = @ color / Blue />
< ImageView
android:id = @ + id / imageView2
android:layout_width = match_parent
android:layout_height = wrap_content
android:layout_marginLeft = 10dp
android:layout_marginRight = 10dp
android:layout_marginTop = 10dp
android:scaleType = fitXY
android:src = @ drawable / line_y_h />
< / LinearLayout>
< / ScrollView>
-
对话框代码
public void show_Alert_version_custom(String str,final String url,
final String exitStatus)//用于
{
最终对话框对话框=新的Dialog(Splash.this);
dialog.setContentView(R.layout.version_update);
dialog.setTitle(getString(R.string.alert_title));;
Button dialogButton2 =(按钮)dialog.findViewById(R.id.btn_remind);
dialogButton =(按钮)dialog.findViewById(R.id.btn_upgrade);
ImageView viewLine =(ImageView)dialog.findViewById(R.id.imageView2);
//如果单击了按钮,则关闭自定义对话框
dialogButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(查看v){}
});
//如果单击了按钮,则关闭自定义对话框
dialogButton2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){ }
});
dialog.show();
}
解决方案< ScrollView中的/ div>
android:fillViewport = true解决了我的问题。现在,它甚至可以在对话框中滚动。
I am inflating a layout inside a dialog, which consist of a scrollview but the layout is not scrolling. I have referred so many questions from stackoverflow but then also its not working. My layout.xml is given below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="@color/White"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/White"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:text="Update available"
android:textColor="#000000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:text="@string/upgrade_msg"
android:textColor="#000000" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_margin="3dp"
android:layout_weight="0.02"
android:src="@drawable/updateimg2" />
<Button
android:id="@+id/btn_upgrade"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_forget_pwd"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@color/White"
android:gravity="center"
android:text="Upgrade Now"
android:textColor="@color/Black" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="@drawable/line_y_h" />
<Button
android:id="@+id/btn_remind"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_forget_pwd"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@color/White"
android:gravity="center"
android:text="Remind Me Later"
android:textColor="@color/Blue" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="@drawable/line_y_h" />
</LinearLayout>
</ScrollView>
Dialog code
public void show_Alert_version_custom(String str, final String url, final String exitStatus)// use for { final Dialog dialog = new Dialog(Splash.this); dialog.setContentView(R.layout.version_update); dialog.setTitle(getString(R.string.alert_title)); Button dialogButton2 = (Button) dialog.findViewById(R.id.btn_remind); dialogButton = (Button) dialog.findViewById(R.id.btn_upgrade); ImageView viewLine = (ImageView) dialog.findViewById(R.id.imageView2); // if button is clicked, close the custom dialog dialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {} }); // if button is clicked, close the custom dialog dialogButton2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {} }); dialog.show(); }
解决方案
android:fillViewport="true" in ScrollView solved my problem. Now its scrolling even inside dialog.
这篇关于在对话框中使用Scrollview时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文