2016-10-27 1 views
0

Ich habe ein Problem in der Größe des Bildes in meinem TextView. Es wird das Symbol nicht angezeigt. Ich möchte, dass meine Icon-Größe so ist und mit dem Text icon with text Ich weiß nicht, was das Problem meines Codes ist, warum es nicht angezeigt wird.Größe ändern Symbol in Textansicht mit Text Symbol wird nicht angezeigt

<?xml version="1.0" encoding="utf-8"?> 
<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="200dp" 
      android:orientation="horizontal" 
      android:background="#eeeeee" android:layout_marginTop="30dp"> 

     <TextView 
       android:id="@+id/mytxview1" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginBottom="5dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="2dp" 
       android:layout_weight="1" 
       android:adjustViewBounds="true" 
       android:padding="30dp" 
       android:scaleType="fitCenter" 
       android:background="@drawable/button1_style" 
       android:drawableTop="@drawable/icon1_48dp" 
       style="@style/Widget.AppCompat.Button.Colored" 
       android:text = "Button 1" 


     /> 


     <TextView 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginBottom="5dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="2dp" 
       android:layout_weight="1" 
       android:adjustViewBounds="true" 
       android:padding="30dp" 
       android:scaleType="fitCenter" 
       style="@style/Widget.AppCompat.Button.Colored" 
       android:background="@drawable/button2_style" 
       android:drawableTop="@drawable/icon2_48dp" 
       android:tint="#ffffff" 
       android:text = "Button 2" 

       /> 

    </LinearLayout> 

    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:orientation="horizontal" 
      android:background="#eeeeee" android:layout_marginBottom="20dp"> 

    <TextView 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginBottom="5dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="2dp" 
       android:layout_weight="1" 
       android:adjustViewBounds="true" 
       android:padding="30dp" 
       android:scaleType="fitCenter" 
       style="@style/Widget.AppCompat.Button.Colored" 
       android:drawableTop="@drawable/icon3_48dp" 
       android:background="@drawable/button3_style" 
       android:tint="#ffffff" 
       android:text = "Button 3" 
       /> 

     <TextView 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginBottom="5dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="2dp" 
       android:layout_weight="1" 
       android:adjustViewBounds="true" 
       android:padding="30dp" 
       android:scaleType="fitCenter" 
       style="@style/Widget.AppCompat.Button.Colored" 
       android:drawableTop="@drawable/icon4_48dp" 
       android:background="@drawable/button4_style" 
       android:text = "Button 4" 
       /> 
    </LinearLayout> 

</LinearLayout> 

hier ist, wie ich die Größe:

public class MyClass extends AppCompatActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.my_layout); 

    TextView txt1 = (TextView) findViewById(R.id.mytxview1); 
    Drawable icon = ContextCompat.getDrawable(this,R.drawable.button_style); 
    icon.setBounds(0, 0, 50, 50); 
    txt1.setCompoundDrawables(icon,null,null,null); 
    } 
} 

Vielen Dank im Voraus.

+0

Ich denke, Sie können '' Button'' mit '' drawable'' innen versuchen? –

+0

taste dann android: drawableTop? – jemz

+0

ja können Sie versuchen –

Antwort

1

Versuchen Sie es.

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

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:layout_alignParentTop="true" 
    android:background="@color/colorPrimary" 
    android:elevation="@dimen/toolElvation"> 

    <TextView 
     android:id="@+id/tvHeaderTitle" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:text="@string/action_home" 
     android:textColor="@android:color/white" 
     android:textSize="@dimen/textsize_18" 
     android:textStyle="bold" 
     android:typeface="sans" /> 
</android.support.v7.widget.Toolbar> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.36" 
    android:orientation="horizontal" 
    android:weightSum="1" 
    android:padding="@dimen/scale_5dp"> 

    <LinearLayout 
     android:layout_width="0dip" 
     android:layout_height="match_parent" 
     android:layout_weight="0.495" 
     android:background="@drawable/bg_with_grayborder" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:padding="@dimen/scale_5dp"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="@dimen/scale_5dp" 
      android:src="@drawable/my_warranty" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/scale_10dp" 
      android:gravity="center" 
      android:padding="@dimen/scale_1dp" 
      android:text="@string/my_warranty" 
      android:textAllCaps="true" 
      android:textColor="@android:color/black" 
      android:textSize="@dimen/textsize_14" 
      android:textStyle="bold" /> 


    </LinearLayout> 

    <View 
     android:layout_width="@dimen/scale_5dp" 
     android:layout_height="match_parent" /> 

    <LinearLayout 
     android:layout_width="0dip" 
     android:layout_height="match_parent" 
     android:layout_weight="0.495" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:padding="@dimen/scale_5dp" 
     android:background="@drawable/bg_with_grayborder"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="@dimen/scale_5dp" 
      android:src="@drawable/my_warranty" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/scale_10dp" 
      android:gravity="center" 
      android:padding="@dimen/scale_1dp" 
      android:text="@string/my_warranty" 
      android:textAllCaps="true" 
      android:textColor="@android:color/black" 
      android:textSize="@dimen/textsize_14" 
      android:textStyle="bold" /> 


    </LinearLayout> 

</LinearLayout> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/scale_5dp" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.36" 
    android:orientation="horizontal" 
    android:weightSum="1" 
    android:padding="@dimen/scale_5dp"> 

    <LinearLayout 
     android:layout_width="0dip" 
     android:layout_height="match_parent" 
     android:layout_weight="0.495" 
     android:background="@drawable/bg_with_grayborder" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:padding="@dimen/scale_5dp"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="@dimen/scale_5dp" 
      android:src="@drawable/my_warranty" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/scale_10dp" 
      android:gravity="center" 
      android:padding="@dimen/scale_1dp" 
      android:text="@string/my_warranty" 
      android:textAllCaps="true" 
      android:textColor="@android:color/black" 
      android:textSize="@dimen/textsize_14" 
      android:textStyle="bold" /> 


    </LinearLayout> 

    <View 
     android:layout_width="@dimen/scale_5dp" 
     android:layout_height="match_parent" /> 

    <LinearLayout 
     android:layout_width="0dip" 
     android:layout_height="match_parent" 
     android:layout_weight="0.495" 
     android:background="@drawable/bg_with_grayborder" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:padding="@dimen/scale_5dp"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="@dimen/scale_5dp" 
      android:src="@drawable/my_warranty" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/scale_10dp" 
      android:gravity="center" 
      android:padding="@dimen/scale_1dp" 
      android:text="@string/my_warranty" 
      android:textAllCaps="true" 
      android:textColor="@android:color/black" 
      android:textSize="@dimen/textsize_14" 
      android:textStyle="bold" /> 


    </LinearLayout> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.26" 
    android:orientation="horizontal" 
    android:weightSum="1" 
    android:padding="@dimen/scale_5dp"> 

    <View 
     android:layout_width="0dip" 
     android:layout_height="match_parent" 
     android:layout_weight="0.15" 
     android:background="@android:color/white"/> 

    <LinearLayout 
     android:id="@+id/lntltProductUse" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.70" 
     android:background="@android:color/white" 
     android:orientation="horizontal" 
     android:layout_gravity="center" 
     android:weightSum="1"> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_weight="0.60" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/my_warranty" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/scale_10dp" 
       android:gravity="center" 
       android:padding="@dimen/scale_1dp" 
       android:text="@string/my_warranty" 
       android:textAllCaps="true" 
       android:textColor="@android:color/black" 
       android:textSize="@dimen/textsize_14" 
       android:textStyle="bold" /> 

     </LinearLayout> 


     <TextView 
      android:layout_width="0dp" 
      android:layout_weight="0.40" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="@dimen/scale_10dp" 
      android:padding="@dimen/scale_1dp" 
      android:text="@string/my_warranty" 
      android:textAllCaps="true" 
      android:textColor="@android:color/black" 
      android:textSize="@dimen/textsize_14" 
      android:textStyle="bold" 
      /> 

    </LinearLayout> 

    <View 
     android:layout_width="0dip" 
     android:layout_height="match_parent" 
     android:layout_weight="0.15" 
     android:background="@android:color/white"/> 

</LinearLayout> 

</LinearLayout> 

bg_with_grayborder

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 

<corners 
    android:bottomLeftRadius="20dip" 
    android:bottomRightRadius="20dip" 
    android:radius="20dip" 
    android:topLeftRadius="20dip" 
    android:topRightRadius="20dip" /> 

<stroke 
    android:color="@color/sub_text" 
    android:width="1dip" /> 

<solid android:color="@android:color/white" /> 
</shape> 

Sie könnten Ihre Farbe in <solid android:color="@android:color/white" /> verwenden.

+0

kann ich meinen Buttonstyle verwenden? – jemz

+0

@jemz Was ist dein Button-Stil? und überprüfe auch meine Bearbeitung. –

+0

wo kann ich diese @ Dimen/ToolElvation bekommen? – jemz

Verwandte Themen