【发布时间】:2015-08-05 10:47:54
【问题描述】:
我正在使用 TranslateAnimation 使片段 (GoogleMap) 向下滑动,从而为 EditText 和 TextView 提供空间以使其可见。 所以我用了这个:
文本:文本视图
编辑:编辑文本
MapLayout:一个包含地图的LinearLayout
Animation animation = new TranslateAnimation(
MapLayout.getX(), MapLayout.getY(),MapLayout.getY(), text.getHeight()+edit.getHeight());
问题是我无法制作幻灯片,因为 text.getHeight()+edit.getHeight() 返回 0 所以没有幻灯片! 我尝试使用数字(例如 100),制作了幻灯片,但是设备之间有所不同,我在 Galaxy S3 上测试过,幻灯片不完整,EditText 仍有一部分不可见,至于模拟器它工作正常。 当我试图让数字更大一点时,幻灯片会更长(例如 200),嗯...幻灯片对 S3 很好,但我对模拟器很大。
所以我想知道的是,如果有任何方法可以使幻灯片移动到一个点,而不依赖于设备,我的意思是不使用像素;所以幻灯片可以在任何设备上完美运行/
我希望我的问题很清楚。 谢谢
更新:如果这有帮助,我不知道,我添加了一条 Toast 消息,显示 EditText 和 TextView 的高度,在 Emulator 中显示为:85,在 S3 中显示为 181 所以是的,我需要像我说的那样让地图在任何设备中向下滑动
主活动:
protected Animation animation;
protected LinearLayout MapLayout;
protected EditText edit;
protected TextView text;
MapLayout = (LinearLayout)findViewById(R.id.MapLayout);
edit = (EditText)findViewById(R.id.Recherche);
text = (TextView)findViewById(R.id.CaptionRecherche);
Toast.makeText(context, "Height: "+(edit.getHeight()+text.getHeight()), 1000).show();
animation = new TranslateAnimation(MapLayout.getX(), MapLayout.getY(), MapLayout.getY(), text.getHeight()+edit.getHeight());
animation.setDuration(1000);
animation.setFillAfter(true);
MapLayout.startAnimation(animation);
主要 XML:
------- 我正在使用 DrawerLayout...我在应用程序中显示了一个幻灯片菜单...仅供您参考-------
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include
android:id="@+id/ContenuPrincipal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/activity_main_relative"
/>
<!-- ListView... La liste des options du menu -->
<ListView
android:id="@+id/Menu"
android:layout_width="250dp"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
android:layout_gravity="start"
android:background="#333"
android:divider="#666"
android:dividerHeight="1dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
/>
</android.support.v4.widget.DrawerLayout>
Main2 XML(我在上面包含的那个):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8">
<!-- Champs de saisie pour effectuer la recherche: -->
<TextView
android:id="@+id/CaptionRecherche"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Entrer l'emplacement que vous cherchez: "
android:textSize="20sp"
android:layout_marginTop="7dp"
android:layout_marginLeft="20dp"
/>
<EditText
android:id="@+id/Recherche"
android:layout_width="250dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:hint="Salle, Deparetement..."
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:maxLength="100"
android:maxLines="1"
android:layout_below="@id/CaptionRecherche"/>
<!-- La map: -->
<LinearLayout
android:id="@+id/MapLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</RelativeLayout>
【问题讨论】:
标签: android translate-animation