2017-06-04 9 views
-2

Facebookのようなコメントを表示するxmlを使用して、Androidスタジオで作業しています。私の問題は、ボタンの一つであるcomment_more_optionsボタンがAndroid Studioに付属しているエミュレータ上の私の実際のデバイス実行では表示されないのですが、xmlプレビューに表示されます。しかし、ボタンがどこにあるかをクリックすると、アプリが実行されて、それに接続されているメニューが正しく表示されます。私は間違って何をしていますか?イメージボタンが表示されず、クリック時に動作しています

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    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_weight="0" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/comment_profile_picture" 
      android:layout_width="40sp" 
      android:layout_height="40sp" 
      android:layout_gravity="left|center_vertical" 
      android:layout_margin="12dp" 
      android:layout_weight="0.26" 
      app:srcCompat="@mipmap/ic_launcher" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/comment_displayName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left|center_vertical" 
       android:layout_margin="4dp" 
       android:layout_weight="1" 
       android:gravity="bottom|left" 
       android:text="Display Name" 
       android:textAppearance="@android:style/TextAppearance.Material.Menu" /> 

      <TextView 
       android:id="@+id/comment_handle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left|center_vertical" 
       android:layout_marginBottom="6dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="6dp" 
       android:layout_marginTop="2dp" 
       android:layout_weight="1" 
       android:gravity="top|left" 
       android:text="Handle" /> 

     </LinearLayout> 

     <ImageButton 
      android:id="@+id/comment_more_options" 
      android:layout_width="32dp" 
      android:layout_height="32dp" 
      android:layout_gravity="left" 
      android:layout_margin="1dp" 
      android:layout_weight="0.50" 
      android:background="@android:color/transparent" 
      android:visibility="visible" 
      app:srcCompat="@drawable/ic_more_vert_black_24dp" /> 

    </LinearLayout> 

    <TextView 
     android:id="@+id/comment_content" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:text="@string/enter_comment" 
     android:textSize="18sp" /> 

</LinearLayout> 

答えて

1

#です。アトリビュートandroid:weightSum="1.76"を子供LinearLayoutに追加します。

app:srcCompat="@drawable/ic_more_vert_black_24dp"の代わりに、属性android:src="@drawable/ic_more_vert_black_24dp"を使用してください。

これを試してください:あなたはまた、RelativeLayoutを使用することができます

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    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:orientation="horizontal" 
     android:weightSum="1.76"> 

     <ImageView 
      android:id="@+id/comment_profile_picture" 
      android:layout_width="40sp" 
      android:layout_height="40sp" 
      android:layout_gravity="left|center_vertical" 
      android:layout_margin="12dp" 
      android:layout_weight="0.26" 
      android:src="@mipmap/ic_launcher" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/comment_displayName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left|center_vertical" 
       android:layout_margin="4dp" 
       android:layout_weight="1" 
       android:gravity="bottom|left" 
       android:text="Display Name" 
       android:textAppearance="@android:style/TextAppearance.Material.Menu" /> 

      <TextView 
       android:id="@+id/comment_handle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left|center_vertical" 
       android:layout_marginBottom="6dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="6dp" 
       android:layout_marginTop="2dp" 
       android:layout_weight="1" 
       android:gravity="top|left" 
       android:text="Handle" /> 

     </LinearLayout> 

     <ImageButton 
      android:id="@+id/comment_more_options" 
      android:layout_width="32dp" 
      android:layout_height="32dp" 
      android:layout_gravity="left" 
      android:layout_margin="1dp" 
      android:layout_weight="0.50" 
      android:background="@android:color/transparent" 
      android:visibility="visible" 
      android:src="@drawable/ic_more_vert_black_24dp" /> 

    </LinearLayout> 

    <TextView 
     android:id="@+id/comment_content" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:text="Enter Comment" 
     android:textSize="18sp" /> 

</LinearLayout> 

。次に例を示します。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:id="@+id/comment_profile_picture" 
      android:layout_width="40sp" 
      android:layout_height="40sp" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_margin="12dp" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageButton 
      android:id="@+id/comment_more_options" 
      android:layout_width="32dp" 
      android:layout_height="32dp" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="8dp" 
      android:background="@android:color/transparent" 
      android:visibility="visible" 
      android:src="@drawable/ic_camera" /> 

     <LinearLayout 
      android:id="@+id/layout_middle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_toRightOf="@+id/comment_profile_picture" 
      android:layout_toLeftOf="@+id/comment_more_options" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="8dp" 
      android:layout_centerVertical="true"> 

      <TextView 
       android:id="@+id/comment_displayName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Display Name" 
       android:textAppearance="@android:style/TextAppearance.Material.Menu" /> 

      <TextView 
       android:id="@+id/comment_handle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left|center_vertical" 
       android:layout_marginTop="2dp" 
       android:text="Handle" /> 

     </LinearLayout> 
    </RelativeLayout> 

    <TextView 
     android:id="@+id/comment_content" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:text="Enter Comment" 
     android:textSize="18sp" /> 

</LinearLayout> 

OUTPUT:

enter image description here

これは代わりに〜

0

使用して、これを助けることを願っています:

アンドロイド:SRC =」 @ drawable/ic_more_vert_black_24dp "

また、アイコンの色が背景と同じでないことを確認してください。

関連する問題