2016-07-15 2 views
2

мое изображение не будет использоваться с помощью кода «android: layout_centerHorizontal», даже используя гравитацию, не разрешит его. Есть ли другой способ или есть неправильные входы в моем режиме релятивирования и прокрутки.Изображение не будет сосредоточено на андроиде: layout_centerHorizontal

scale layout bounds landscape view of with scale layout bounds размер экрана 768x1280 нексус api23

Я не проблемы с андроид версии 4, может быть, это связано с апи? так как мой минимальный sdk - версия Android 2?

Вот код:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:fillViewport="true" 
android:layout_height="fill_parent"> 
<RelativeLayout 
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.capstone.jmilibraryapp.Login"> 


<EditText 
    android:layout_width="300dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/etUsername" 
    android:hint="Enter Sr-Code" 
    android:layout_below="@+id/imageView3" 
    android:layout_centerHorizontal="true" /> 
<ImageView 
    android:layout_centerHorizontal="true" 
    android:layout_width="500dp" 
    android:layout_height="200dp" 
    android:src="@drawable/jmilogo" 
    android:id="@+id/imageView3" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<EditText 
    android:layout_width="300dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/etPassword" 
    android:inputType="textPassword" 
    android:hint="Password" 
    android:layout_below="@+id/etUsername" 
    android:layout_centerHorizontal="true" /> 

<Button 
    android:layout_width="300dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/bLogin" 
    android:text="Log In" 
    android:layout_below="@+id/etPassword" 
    android:layout_alignLeft="@+id/etPassword" 
    android:layout_alignStart="@+id/etPassword" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:text="Log In as Guest" 
    android:id="@+id/guest" 
    android:layout_marginTop="20dp" 
    android:layout_below="@+id/bLogin" 
    android:layout_centerHorizontal="true" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:text="Log In as Guest" 
    android:id="@+id/testinguser" 
    android:layout_marginTop="20dp" 
    android:layout_below="@+id/guest" 
    android:layout_centerHorizontal="true" 
    /> 


</RelativeLayout> 
</ScrollView> 
+0

что вы хотите ?? я имею в виду, что вы хотите поместить изображение позади EditText ?? –

+0

@uttampanchasara sir Я добавил изображение извините за поздний ответ У меня медленное подключение к Интернету у себя дома. –

ответ

0

Вероятно, ваши don't изображения имеют такое же отношение вашего ImageView, вы можете проверить это позволяет showLayoutBounds в инструменты разработчика в устройстве. Вы увидите реальный размер изображения.

Чтобы решить эту проблему, вы можете сделать изображение ImageView пропорциональным для вашего ImageView или ad scaleType = "fitCenter" для вашего ImageView.

+0

Да, возможно, я должен изменить размер изображения? Я обновил свой пост, кстати, может быть, у меня проблема с версиями api? –

+0

@ starcabanig удалить android: layout_alignParentLeft = "true" android: layout_alignParentStart = "true" из вашего ImageView. Он переопределяет центральное горизонтальное поведение. – jonathanrz

+1

это ответ, я проголосовал, но может показаться публично видеть оценку из-за моей репутации ниже 15. Спасибо, кстати ^^ –

0

Try ниже XML это работа со мной ..

Outout

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 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:layout_centerHorizontal="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="20dp" 
     android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/imageView3" 
      android:layout_width="wrap_content" 
      android:layout_height="200dp" 
      android:layout_gravity="center_horizontal" 
      android:layout_weight="1" 
      android:scaleType="fitCenter" 
      android:src="@drawable/school" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="20dp" 
      android:layout_weight="1"> 

      <EditText 
       android:id="@+id/etUsername" 
       android:layout_width="300dp" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:hint="Enter Sr-Code" /> 

      <EditText 
       android:id="@+id/etPassword" 
       android:layout_width="300dp" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/etUsername" 
       android:layout_centerHorizontal="true" 
       android:hint="Password" 
       android:inputType="textPassword" /> 

      <Button 
       android:id="@+id/bLogin" 
       android:layout_width="300dp" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@+id/etPassword" 
       android:layout_alignStart="@+id/etPassword" 
       android:layout_below="@+id/etPassword" 
       android:text="Log In" /> 

      <TextView 
       android:id="@+id/guest" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/bLogin" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="20dp" 
       android:text="Log In as Guest" 
       android:textAppearance="?android:attr/textAppearanceSmall"/> 

      <TextView 
       android:id="@+id/testinguser" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/guest" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="20dp" 
       android:text="Log In as Guest" 
       android:textAppearance="?android:attr/textAppearanceSmall"/> 

     </RelativeLayout> 
    </LinearLayout> 
</ScrollView> 
+0

сэр Я пробовал свой код, и я получаю эту ошибку "java.lang.RuntimeException: Unable для запуска Activity ComponentInfo {com.capstone.jmilibraryapp/com.capstone.jmilibraryapp.Login}: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageView не может быть добавлен в android.widget.EditText на android.app. ActivityThread.performLaunchActivity (ActivityThread.java:2416) «возможно, у меня проблема с appcompactview? –

+0

Я обновил мое сообщение, пожалуйста, прочитайте его спасибо ^^ –

+0

попробуйте использовать библиотеку suport 7 ur, используя устаревшую версию –