-4

検索アイコンの下に検索テキストが必要です。検索アイコン+テキストグループは、画面の中央に配置する必要があります。私はをしたいリニアレイアウトのセンター画像ビューとテキストビュー

:____________のように見え、実際にどのような画面:私は直接の下にリストビューを必要とするので、私はリニアレイアウトを使用:

enter image description here enter image description here

注意。これは検索バーに使用されます。 TextViewのandroid:drawableTopを使っている人にとって、私はそれを試みましたが、画像が小さすぎる(画像を500pxに設定したとしても)か、画像ビューで "100dpx100dp"と設定したときです。

コード

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_gravity="center_horizontal" 
      app:srcCompat="@drawable/ic_search_gray_500px" /> 

     <TextView 
      android:id="@+id/searchTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/search_hint" 
      android:layout_gravity="center_horizontal" 
      tools:layout_editor_absoluteX="130dp" 
      tools:text="@string/search_hint" /> 

    </android.support.constraint.ConstraintLayout> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 


</LinearLayout> 

Reference

+0

とどのようなリストビューについて – Prem

答えて

2

を:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:orientation="vertical"> 

      <ImageView 
       android:id="@+id/imageView" 
       android:layout_width="100dp" 
       android:layout_height="100dp" 
       android:layout_gravity="center_horizontal" 
       android:src="@drawable/app_logo_main" /> 

      <TextView 
       android:id="@+id/searchTextView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Search" 
       android:textAlignment="center" 
       android:textColor="@color/colorPrimary" /> 

     </LinearLayout> 

    </RelativeLayout> 
1

あなたはRelativeLayoutを使用することができます。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

     <RelativeLayout 
      android:id="@+id/rlROOT" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      > 

      <ImageView 
       android:id="@+id/imageView" 
       android:layout_width="100dp" 
       android:layout_height="100dp" 
       android:layout_centerInParent="true" 
       android:gravity="center_vertical" 
       android:src="@drawable/ic_search_gray_500px" /> 

      <TextView 
       android:id="@+id/textView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/imageView" 
       /> 
     </RelativeLayout> 

     <ListView 
     android:id="@android:id/list" 
     android:layout_below="@+id/rlROOT" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</RelativeLayout> 
+2

代わりの異なるよりもリストビューを配置する場所を我々はアンドロイドを使用することができますImageVIew:drawab leTop = "@ drawable/ic_search_gray_500px" あなたはどう思いますか? – Shekhar

+0

@Shekhar問題はありません。 –

2

TextViewのみで使用します.TextViewでは、1つの属性にdrawableTopがあり、それをイメージ用に使用します。イメージとテキストの間に間隔を空けたい場合は、drawablePaddingを使用します。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/searchTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableTop="@drawable/ic_search_gray_500px" 
      android:text="@string/search_hint" 
      android:layout_centerInParent="true /> 

    <ListView 
     android:layout_below="searchTextView" 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</RelativeLayout> 
+0

私はそれを試みましたが、画像は非常に小さいです(画像を500pxに設定しても)vsを画像ビューで「100dpx100dp」と設定したとき - わからない理由 – Alex

2

この試してください:あなたの問題を解決するコードの下

enter image description here

<?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"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:visibility="gone"> 

      <ImageView 
       android:id="@+id/imageView" 
       android:layout_width="100dp" 
       android:layout_height="100dp" 
       android:layout_gravity="center_horizontal" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:id="@+id/searchTextView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/search_hint" 
       android:textAlignment="center" 
       android:textColor="@color/colorBlack" /> 


     </LinearLayout> 

     <ListView 
      android:id="@android:id/list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 




</LinearLayout> 
</RelativeLayout> 
+0

もしこの記事があなたにアップヴォート正しいとマークしてください。 –

関連する問題