Android 在活动之间传递可绘制的图像看起来是拉伸的
我正在构建一个应用程序,其中我有一个带有imageview和textview的listview,当我单击一个列表项时,我希望将名称和图像传递给其他活动 我已经成功地做到了这一点,但当我在另一个活动中传递图像时,图像看起来被拉伸了。如何解决这个问题 我使用安卓资产工作室使我下载的图像可以在所有大小 在listview中,图像看起来很好,但在其他活动中,图像看起来拉伸 这是我的密码:Android 在活动之间传递可绘制的图像看起来是拉伸的,android,android-layout,listview,android-intent,Android,Android Layout,Listview,Android Intent,我正在构建一个应用程序,其中我有一个带有imageview和textview的listview,当我单击一个列表项时,我希望将名称和图像传递给其他活动 我已经成功地做到了这一点,但当我在另一个活动中传递图像时,图像看起来被拉伸了。如何解决这个问题 我使用安卓资产工作室使我下载的图像可以在所有大小 在listview中,图像看起来很好,但在其他活动中,图像看起来拉伸 这是我的密码: ListView lv = (ListView) findViewById(R.id.listView);
ListView lv = (ListView) findViewById(R.id.listView);
ArrayAdapter<ListaAdapterNext> adapter = new MySpecialAdapter();
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(NextActivity.this, ListItemActivity.class);
intent.putExtra("name", skonakia.get(position).getItemNextName().toString());
intent.putExtra("icon", skonakia.get(position).getImageNextId());
intent.putExtra("usage", skonakia.get(position).getItemUsage());
intent.putExtra("description", skonakia.get(position).getItemDescription());
startActivity(intent);
}
});
下面是我在listview和其他活动中使用的两种布局,当有人单击listitem时
列表视图布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textViewListItem"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:layout_gravity="center_horizontal" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="-40dp"
android:id="@+id/imageView"
android:src="@drawable/ic_app" />
</LinearLayout>
ListItemClicked布局:
<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"
tools:context="com.example.kostas.myapplication.ListItemActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:weightSum="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/imageViewListItem"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/description"
android:id="@+id/textView" />
<TextView
android:id="@+id/description"
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" />
<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginTop="20dp"
android:layout_alignParentLeft="true"
android:background="#000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/usage"
android:id="@+id/textView2"
android:layout_marginTop="20dp"
android:layout_marginBottom="-15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/usage"
android:layout_marginTop="25dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/buy"
android:id="@+id/buyButton"
android:layout_marginTop="50dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
注意:在使用JELLY_BEAN之前,此函数无法正确检索
在此处传递资源ID时的最终配置密度为
另一个可绘制资源的别名。这意味着如果密度
别名资源的配置与实际配置不同
资源,则返回的可提取数据的密度将不正确,
导致不良的缩放。为了解决这个问题,你可以
通过TypedArray.getDrawable检索可绘制文件。使用
Context.obtainStyledAttributes与包含资源的数组
创建TypedArray的感兴趣的ID
这可能是你的问题吗
注意:在使用JELLY_BEAN之前,此函数无法正确检索
在此处传递资源ID时的最终配置密度为
另一个可绘制资源的别名。这意味着如果密度
别名资源的配置与实际配置不同
资源,则返回的可提取数据的密度将不正确,
导致不良的缩放。为了解决这个问题,你可以
通过TypedArray.getDrawable检索可绘制文件。使用
Context.obtainStyledAttributes与包含资源的数组
创建TypedArray的感兴趣的ID
这可能是你的问题吗?你为什么不把可提取数组转换成bytearray,通过put把bytearray转换成intent,然后把你的可提取数组取回呢?你为什么不把可提取数组转换成bytearray,通过put把bytearray转换成intent,然后取回你的可提取数组呢问题莫,我会试试看,但我不认为这是问题迈尔斯的文件。。。使用位图工厂…我认为它应该做的工作…给它一个tryYes文件KostasMatrix。。。使用位图工厂…我认为它应该做的工作…给它一个尝试
<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"
tools:context="com.example.kostas.myapplication.ListItemActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:weightSum="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/imageViewListItem"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/description"
android:id="@+id/textView" />
<TextView
android:id="@+id/description"
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" />
<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginTop="20dp"
android:layout_alignParentLeft="true"
android:background="#000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/usage"
android:id="@+id/textView2"
android:layout_marginTop="20dp"
android:layout_marginBottom="-15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/usage"
android:layout_marginTop="25dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/buy"
android:id="@+id/buyButton"
android:layout_marginTop="50dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>