Java imageswitcher填充屏幕(但我不希望它这样做)[android]
我在我的寄存器片段中添加了一个imageswitcher,当用户选择他/她的性别时,图像会发生变化,但显示的图像太大,我无法缩放它。我使用的是scrollview,但Imageswitcher比屏幕大并不好。我尝试使用更小的图像,但结果是一样的。以下是我的XML:Java imageswitcher填充屏幕(但我不希望它这样做)[android],java,android,scale,imageswitcher,Java,Android,Scale,Imageswitcher,我在我的寄存器片段中添加了一个imageswitcher,当用户选择他/她的性别时,图像会发生变化,但显示的图像太大,我无法缩放它。我使用的是scrollview,但Imageswitcher比屏幕大并不好。我尝试使用更小的图像,但结果是一样的。以下是我的XML: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/registerbackground"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/kayit_kayit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/register"
android:textColor="#FFFFFFFF"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="@+id/kayit_ad"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="@string/hintAd"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="@+id/kayit_soyad"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="@string/hintSoyad"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="@+id/kayit_email"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="@string/hintEmail"
android:inputType="textEmailAddress"
android:textColor="#FFFFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/kayitKiz"
android:textColor="#FFFFFFFF" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/kayitErkek"
android:textColor="#FFFFFFFF" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageSwitcher
android:id="@+id/cinsiyetSwitcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ImageSwitcher>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="@+id/kayit_kelime1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="50dp"
android:hint="@string/hintKelimeler1"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF"/>
<EditText
android:id="@+id/kayit_kelime2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/hintKelimeler2"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF"/>
<EditText
android:id="@+id/kayit_kelime3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="50dp"
android:hint="@string/hintKelimeler3"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
将
ImageSwitchers
宽度更改为wrap\u content
无效。我添加了代码以在.java文件中扩展它。它缩放了图像,但Imageswitcher仍然很大。在imageswitcher前后都有一个很大的空间。这是因为您将每个视图包装在一个线性布局中,这是错误的。嗯,我应该怎么做呢?删除所有具有一个子视图的视图组(线性布局),并将重力和填充/边距移动到视图本身。
....
cinsiyetSwitcher = (ImageSwitcher) rootView.findViewById(R.id.cinsiyetSwitcher);
cinsiyetSwitcher.setFactory(new ViewFactory() {
@Override
public View makeView() {
ImageView imageView = new ImageView(getActivity());
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
return imageView;
}
});
kizRadio = (RadioButton) rootView.findViewById(R.id.radio0);
erkekRadio = (RadioButton) rootView.findViewById(R.id.radio1);
kizRadio.setOnClickListener( new View.OnClickListener() {
public void onClick(View v)
{
degistir1(v);
}
});
erkekRadio.setOnClickListener( new View.OnClickListener() {
public void onClick(View v)
{
degistir2(v);
}
});
....
public void degistir1(View view)
{
Animation in = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_in_left);
Animation out = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_out_right);
cinsiyetSwitcher.setInAnimation(in);
cinsiyetSwitcher.setOutAnimation(out);
cinsiyetSwitcher.setImageResource(R.drawable.kari);
}
public void degistir2(View view)
{
Animation in = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_out_right);
Animation out = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_in_left);
cinsiyetSwitcher.setInAnimation(out);
cinsiyetSwitcher.setOutAnimation(in);
cinsiyetSwitcher.setImageResource(R.drawable.adam);
}