【问题标题】:How to Resize scrollview?如何调整滚动视图的大小?
【发布时间】:2014-05-29 09:42:41
【问题描述】:

我在屏幕顶部有一些ImageButton,在它们下方有一个Scrollview。 (XML 是RelativeLayout) 我想调整Scrollview 的大小,它在哪里。 我使用此代码:

scrollview.setLayoutParams(new RelativeLayout.LayoutParams(200,200)) ;

Scrollview 调整大小,但它移动到屏幕顶部。 我想调整ScrollView 的大小。 我不希望它移动到顶部。 我使用什么代码?

完整的 XML 和 JavaCode 在这里:

p30droid.com/Thread-تغییر-اندازه-اسکرول-ویو-و-imagebutton-و-button

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context=".MainActivity" >

 <LinearLayout
 android:id="@+id/linearLayout1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true" >

 <ImageButton
 android:id="@+id/imageButton1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:src="@drawable/ic_launcher" />

 <ImageButton
 android:id="@+id/imageButton2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:src="@drawable/ic_launcher" />

 <ImageButton
 android:id="@+id/imageButton3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:src="@drawable/ic_launcher" />

 <ImageButton
 android:id="@+id/imageButton4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:src="@drawable/ic_launcher" />
 </LinearLayout>

 <LinearLayout
 android:id="@+id/linearLayout2"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/linearLayout1"
 android:layout_centerHorizontal="true" >

 <ImageButton
 android:id="@+id/imageButton5"
 android:layout_width="50dp"
 android:layout_height="50dp"
 android:src="@drawable/ic_launcher" />

 <ImageButton
 android:id="@+id/imageButton6"
 android:layout_width="50dp"
 android:layout_height="50dp"
 android:src="@drawable/ic_launcher" />
 </LinearLayout>

 <LinearLayout
 android:id="@+id/linearLayout3"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentBottom="true" >

 <Button
 android:id="@+id/button11"
 android:layout_width="140dp"
 android:layout_height="65dp"
 android:text="تغییر سایز" />

 <ImageButton
 android:id="@+id/imageButton8"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:src="@drawable/ic_launcher" />

 <ImageButton
 android:id="@+id/imageButton9"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:src="@drawable/ic_launcher" />
 </LinearLayout>

 <ScrollView
 android:id="@+id/scrollView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/linearLayout2"
 android:layout_above="@+id/linearLayout3"
 android:layout_centerHorizontal="true" >

 <LinearLayout
 android:id="@+id/linearLayout4"
 android:layout_width="match_parent"
 android:layout_height="0dp"
 android:orientation="vertical" >


 <WebView
 android:id="@+id/webView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="#ffffff" />

 </LinearLayout>
 </ScrollView>

</RelativeLayout>

【问题讨论】:

  • 看不到您的 XML 文件

标签: android resize scrollview


【解决方案1】:

为您的滚动条创建一种新的“样式”,然后在您的 XML 文件中导入,例如:

/res/drawable/scroll_vertical.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#9a9a9a" />

    <corners android:radius="5dp" />

    <size android:width="5dp" />

</shape>

主要 XML

android:scrollbarThumbVertical="@drawable/scroll_vertical" >

【讨论】:

    猜你喜欢
    • 2013-03-08
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    相关资源
    最近更新 更多