کلیدستان

نسخه‌ی کامل: اشیاء ثابت در scroll view (بالای Activity ، ثابت و پایین آن، به صورت متحرک) (اندروید)
شما در حال مشاهده نسخه آرشیو هستید. برای مشاهده نسخه کامل کلیک کنید.
با سلام مجدد...
استاد و دوستان عزیز...
اگر بخوام یک شیء به عنوان header در اکتیویتی که خاصیت scroll view داره ایجاد کنم که با بالا و پایین بردن صفخه، این شیء همیشه در بالای صفحه باشه چجوری میشه این ویژگی رو به شیء مربوط داد؟؟؟ چند وقتیه دیگه جواب نمیدید
سلام.
در فایل xml متناظر با Activity ، باید لایه اصلی را به صورت LinearLayout در نظر بگیرید و بعد در آن، عنصرهای که می خواهید به صورت ثابت باشند را قرار داده و سپس یک LinearLayout قرار می دهید که حاوی تگ ScrollView می باشد. من کد زیر را برایتان ذکر می کنم که آن را از یک برنامه که خودم به همین شکل ساختم (یعنی بالای Activity به صورت ثابت و بخش پایین آن، به صورت ScrollView می باشد)، استخراج کردم (کمی کد رو خلاصه کردم و عنصرهای متحرک را باید درون زوج تگ LinearLayout درون ScrollView قرار بدهید (درون زوج تگ ScrollView ، یک زوج تگ LinearLayout قرار داده ایم)، اگر کد مشکلی داشت، بفرمایید تا کد کاملتر را قرار بدهم) :

کد پی‌اچ‌پی:
<LinearLayout 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:orientation="vertical" >
    
    <
Button
        android
:id="@+id/button1"
        
android:layout_width="match_parent"
        
android:layout_height="wrap_content"
        
android:textSize="20sp"
        
android:textColor="#FFF"
        
android:text="Button" />
    
    <
Button
        android
:id="@+id/button1"
        
android:layout_width="match_parent"
        
android:layout_height="wrap_content"
        
android:textSize="20sp"
        
android:textColor="#FFF"
        
android:text="Button" />
    
    <
Button
        android
:id="@+id/button1"
        
android:layout_width="match_parent"
        
android:layout_height="wrap_content"
        
android:textSize="20sp"
        
android:textColor="#FFF"
        
android:text="Button" />
    
    <
LinearLayout 
        android
:layout_width="fill_parent"
        
android:layout_height="fill_parent"
        
android:orientation="vertical" >


        <
ScrollView
            android
:id="@+id/layout"
            
android:layout_width="fill_parent"
            
android:layout_height="fill_parent"
            
android:layout_marginTop="5dip"
            
android:fillViewport="true"
            
android:scrollbarStyle="outsideInset"
            
android:scrollbars="horizontal|vertical" >
            
            <
LinearLayout 
                android
:layout_width="fill_parent"
                
android:layout_height="fill_parent"
                
android:orientation="vertical" >

                <
ImageView
                    android
:id="@+id/imageView1"
                    
android:layout_width="match_parent"
                    
android:layout_height="500dp"
                    
android:src="@drawable/ic_launcher" />
                
                <
ImageView
                    android
:id="@+id/imageView1"
                    
android:layout_width="match_parent"
                    
android:layout_height="500dp"
                    
android:src="@drawable/ic_launcher" />
            
            </
LinearLayout>
    
        </
ScrollView>

    </
LinearLayout>

</
LinearLayout

ممنون از زحمات شما
این کد من هست ولی مشکل داره و اکتیویتی باز نمیشه
مشکل چیه؟

کد پی‌اچ‌پی:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/bck_hdr" />
    
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imageButton1"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="16dp"
        android:layout_toRightOf="@+id/imageView3"
        android:background="@drawable/m1_hdr" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imageButton1"
        android:layout_alignLeft="@+id/imageButton1"
        android:src="@drawable/m2_hdr" />
    
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/bckg_mk"
        android:orientation="vertical" >

        <ScrollView
            android:id="@+id/layout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="5dip"
            android:fillViewport="true"
            android:scrollbarStyle="outsideInset"
            android:scrollbars="horizontal|vertical" >

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageButton1"
        android:layout_below="@+id/imageButton1"
        android:background="@drawable/yaddasht" />

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="14dp"
        android:background="@drawable/maghalat" />

    <ImageButton
        android:id="@+id/imageButton3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageButton2"
        android:layout_centerHorizontal="true"
        android:background="@drawable/mahsoolat" />

    <ImageButton
        android:id="@+id/imageButton4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageButton3"
        android:layout_below="@+id/imageButton3"
        android:background="@drawable/alarm" />

    <ImageButton
        android:id="@+id/imageButton5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageButton4"
        android:layout_centerHorizontal="true"
        android:background="@drawable/chat" />

    <ImageButton
        android:id="@+id/imageButton6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageButton5"
        android:layout_centerHorizontal="true"
        android:background="@drawable/registery"
        android:src="@drawable/registery" />

    <ImageButton
        android:id="@+id/imageButton7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageButton6"
        android:layout_centerHorizontal="true"
        android:background="@drawable/about_mk" />

    <ImageButton
        android:id="@+id/imageButton8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageButton7"
        android:layout_centerHorizontal="true"
        android:background="@drawable/biorhiythms"
        android:src="@drawable/biorhiythms" />

    <ImageButton
        android:id="@+id/imageButton9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageButton8"
        android:layout_centerHorizontal="true"
        android:background="@drawable/about_app" />

    

       </ScrollView>

    </LinearLayout>

</LinearLayout> 
 
کد رو تصحیح کردم . کد جدید را در ارسال اول تست کنید (باید یک LinearLayout به ScrollView افزوده می شد). این بار خودم کد جدید رو تست کردم و مشکلی نداشت.

با سپاااااس فراوان، بله همینطور که فرمودید بود و درست شد

 استاد به جوابتون به این دو تا سوال نیاز شدید هست لطف بفرمایید گوشه چشمی داشته باشید
ممنون
http://kelidestan.com/forum/showthread.php?tid=5114

http://kelidestan.com/forum/showthread.php?tid=5032