我有一个带有特定编辑文字的自定义提醒框。我需要让它Scrollable。我尝试了一些方法,并没有为我工作。这是我的布局..
<?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="fill_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="-2dp"
android:background="#da5959"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
</LinearLayout>
<!--
</LinearLayout>
-->
所以请帮我找一些解决方案。
答案 0 :(得分:1)
这样您可以帮助解决问题。
<ScrollView>
<LinearLayout android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<TextView />
<Button />
</LinearLayout>
</ScrollView>
答案 1 :(得分:0)
请看一下Android的高级对话解决方案:https://github.com/orhanobut/dialogplus
可以替代,它可以轻松处理滚动
答案 2 :(得分:0)
试试这个有效。
MainActivity.Java
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View dialogView = inflater.inflate(R.layout.alert_dialog, null);
// Set the custom layout as alert dialog view
builder.setView(dialogView);
// Get the custom alert dialog view widgets reference
// Create the alert dialog
final AlertDialog dialog = builder.create();
// Set positive/yes button click listener
// Display the custom alert dialog on interface
dialog.show();
alert_dialog.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="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="-2dp"
android:background="#da5959"
android:gravity="center"
android:orientation="horizontal"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
</LinearLayout>
</LinearLayout>
</ScrollView>
答案 3 :(得分:0)
Scrollview需要一个父布局和一个子布局,然后将您的设计放在子布局中,然后滚动工作正常。 试试这段代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="-2dp"
android:background="#da5959"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
</LinearLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test3" />
</LinearLayout>
</ScrollView>
</LinearLayout>