2016-10-17 67 views
-3

I want to doLinearLayout中的Android按钮Fit Left

我想放上上图的按钮。但我有下面的图像。我无法成功。搜索了很多,但无法找到它。

result of code

的LinearLayout中的LinearLayout具有透明背景和有按钮向左的这一点。

Activity.xml:

<?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:background="@drawable/genel_arkaplan" 
android:orientation="vertical" > 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="750dp" 
    android:layout_height="wrap_content" 
    android:paddingLeft="40dp" 
    android:layout_gravity="center_vertical|center_horizontal" 
    android:background="@drawable/lay_transparan_aramasecenek" 
    android:layout_marginTop="100dp"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/lay_transparan_aramasecenek_beyaz"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitCenter" 
     android:background="@drawable/kod_ile_arama" 
     android:id="@+id/imageButton" /> 
    </LinearLayout> 
</LinearLayout> 

+0

将第二个'Linearlayout'的高度和宽度更改为'match_parent'。按钮不需要'android:scaleType =“fitCenter”'也删除_android:paddingLeft =“40dp”_ – Piyush

+0

我这样做,但我有空间左,顶部和底部。你能分享最终的XML吗? – mobileprogramming

回答

1

的LinearLayout标签

+0

删除,但我仍然有线性布局之间的空间 – mobileprogramming

+0

您正在使用的利润率也采取相同的角子机布局和按钮,然后它会适当适合..让我知道一旦完成其他解决方案将给你另一种解决方案 –

+0

好吧谢谢我解决了问题。 lay_transparan_aramasecenek布局有顶部,底部和左边的余量。我删除了利润率没有问题。非常感谢 – mobileprogramming

0

刚刚从你的 “的LinearLayout” 删除下面的代码

android:paddingLeft="40dp" 

这是增加额外填充到父布局。

下面将是您的最终代码。

<?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:background="@drawable/genel_arkaplan" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="750dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical|center_horizontal" 
     android:background="@drawable/lay_transparan_aramasecenek" 
     android:layout_marginTop="100dp"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/lay_transparan_aramasecenek_beyaz"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:scaleType="fitCenter" 
      android:background="@drawable/kod_ile_arama" 
      android:id="@+id/imageButton" /> 
    </LinearLayout> 
</LinearLayout> 
0

删除android:paddingLeft="40dp尝试使用连击结果此代码为您的按钮图标。我希望它对你有帮助。

<?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:background="@color/color_green" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/dimen_50" 
     android:layout_gravity="center" 
     android:layout_marginLeft="@dimen/dimen_10" 
     android:layout_marginRight="@dimen/dimen_10" 
     android:layout_marginTop="100dp" 
     android:background="@android:color/holo_blue_light"> 
     <Button 
      android:id="@+id/imageButton" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:background="@mipmap/ic_share" 
      android:scaleType="fitCenter" /> 

    </RelativeLayout> 
</LinearLayout>