Я использую TranslateAnimation, чтобы сделать фрагмент (GoogleMap), скользящим вниз, чтобы освободить место для EditText и TextView, чтобы они были видны. поэтому я использовал это:
текст: текстовый вид
редактировать: EditText
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, в эмуляторе он говорит: 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>