Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > Android ทำ custom listview ใส่รูปขนนาด Full HD แล้วกระตุก ช่วยแนะนำหน่อยครับ



 

Android ทำ custom listview ใส่รูปขนนาด Full HD แล้วกระตุก ช่วยแนะนำหน่อยครับ

 



Topic : 122389



โพสกระทู้ ( 40 )
บทความ ( 0 )



สถานะออฟไลน์




ตามหัวข้อเลยครับ ใส่รูปเล็กๆ เวลา scroll เลื่อนมันไม่กระตุกน่ะ พอใส่รูปใหญ่ปุ๊บกระตุกเลย ทั้งๆ ที่แค่เปลี่ยนรูปเฉยๆ
ผมลองศึกษาจากหลายๆตัวอย่าง ส่วนมากจะเป็น custom listview แบบรูปเดียวเลยทำให้ไม่กระตุก พอเป็น custom listview รูปแต่ละ listview ไม่ซ้ำกัน และรูปมีขนาดใหญ่ มันกระตุกรัวๆเลย

อันนี้โค้ดครับ

Adapter

Code (Android-Java)
public class custom_adapter extends BaseAdapter{

        public Context mContext;
        public LayoutInflater mInflater;
        public int[] resId;

        public custom_adapter(Context context, int[] resId){
            mContext = context;
            mInflater = LayoutInflater.from(mContext);
            this.resId = resId;
        }
        @Override
        public int getCount() {
            return resId.length;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder holder = null;
            if (convertView == null){
                // load layout
                convertView = mInflater.inflate(R.layout.listview_adap, null);
                holder = new ViewHolder();
                holder.txt1 = (TextView) convertView.findViewById(R.id.text1);

                convertView.setTag(holder);

            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.image = (ImageView) convertView.findViewById(R.id.imgView);
            holder.image.setImageResource(resId[position]);
            holder.txt1.setText(String.valueOf(position) + " : First");

            return convertView;
        }
    }

    public class ViewHolder{
        TextView txt1;
        ImageView image;
    }



MainActivity

Code (Android-Java)
public class MainActivity extends AppCompatActivity {

    private ListView listview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        int[] resId = {R.drawable.batman, R.drawable.ironman, R.drawable.spiderman, R.drawable.superman};
        listview = (ListView) findViewById(R.id.listview_main);
        listview.setAdapter(new custom_adapter(getApplicationContext(), resId));

    }
}


ไฟล์ activity_main.xml

Code (XML)
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.first_home.myapplication.MainActivity">

    <ImageView
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="300px"
        android:src="@mipmap/ic_launcher"/>
    <ListView
        android:id="@+id/listview_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/header"
        >

    </ListView>
</RelativeLayout>



อันนี้ listview_adap.xml (จะแสดงอะไรในหน้า Listview บ้าง)

Code (XML)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/text1"
            android:text="hello"
            android:textSize="20dp"
            android:textColor="#000000"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/text2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:textColor="#000000"
            android:text="Description..."
            android:layout_below="@+id/text1"/>
        <ImageView
            android:id="@+id/imgView"
            android:layout_width="400px"
            android:layout_height="400px"
            android:src="@drawable/menu01"
            android:layout_below="@+id/text2"/>

    </RelativeLayout>


</LinearLayout>




ตอนใช้ Header ด้านบนเป็นรูปหุ่น android จากไฟล์ mipmap/ic_launcher(มีอยู่แล้วในโปรแกรม) เวลา scroll ขึ้น ลง สมูทมาก

ic_launcher

หลังจากนั้นพอเปลี่ยนภาพ header จากรุป android เป็นอีกรูป(รูปแบทแมน) ซึ่งมีขนาดจริงเท่ากับ 1920x1080 เวลา scroll ขึ้น ลง กระตุกรัวๆ เลย แล้วตอนกระตุกมี มันแแจ้งเตือนดังนี้

Skipped 57 frames! The application may be doing too much work on its main thread.

batman1


ภาพอื่นๆ ใน listview เช่นกัน เป็นภาพขนาดและ resolution เล็กๆ แบบพวก hero marvel ที่ผมใส่ใน Listview นั้นเวลา scroll ก็ไม่กระตุกเช่นกัน แต่พอเปลี่ยนเป็นภาพอื่นๆเช่นขนาด 1920x1080 แล้ว พบว่ากระตุกรัวๆ

ผมไม่แน่ใจว่าขนาด resolution หรือขนาดของไฟล์มีผลทำให้กระตุกหรือเปล่า รบกวนแนะนำทีครับ หรือมีวิธีอื่นๆที่ดีกว่า custom listview ก็แนะนำได้เช่นกัน



Tag : Mobile, Android, Mobile









ประวัติการแก้ไข
2016-04-10 11:00:33
2016-04-10 16:47:51
2016-04-10 16:48:21
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-04-10 10:59:28 By : zixzack View : 1265 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ใชพวก Thumbnail ก่อนครับ ตอนที่จะแสดงผลค่อยไปดู Full Image มาแสดงครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-04-11 11:34:20 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Android ทำ custom listview ใส่รูปขนนาด Full HD แล้วกระตุก ช่วยแนะนำหน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่