标签: android-linearlayout

有没有办法在包含按钮的LinearLayout中完全消除填充?

我尝试以下尝试以水平线性布局显示两个按钮,按钮的边缘与线性布局的边框齐平.令我惊讶的是,我发现按钮与线性布局的左,右和底边之间始终存在填充.只有按钮的顶部边缘与线性布局的边框齐平.这是为什么?有没有办法控制这种行为?非常感谢.

<LinearLayout android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#777"
  android:padding="0dip"
  android:layout_margin="0dip">
  <Button android:id="@+id/feeling_done_button"
     android:text="@string/done_button_label"
     android:layout_height="wrap_content"
     android:layout_width="match_parent"
     android:layout_weight="1"
     android:padding="0dip"
     android:layout_margin="0dip"/>
  <Button android:id="@+id/feeling_cancel_button"
     android:text="@string/cancel_button_label"
     android:layout_height="wrap_content"
     android:layout_width="match_parent"
     android:layout_weight="1"
     android:padding="0dip"
     android:layout_margin="0dip"/></LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android padding android-layout android-linearlayout

1
推荐指数
1
解决办法
5905
查看次数

如何告诉布局将所有东西都放到50/50?

我有一个带有两个ListView的垂直线性布局.我希望顶级ListView占据屏幕的50%.我希望底部的listivew占据屏幕的50%.我怎么能用XML做到这一点?

java xml eclipse android android-linearlayout

1
推荐指数
1
解决办法
3563
查看次数

ListView中的LinearLayout

所以我试图在ListView中放置一个有两个TextView的LinearLayout,但是我遇到了麻烦,程序一直在用我试过的东西崩溃.ListView只有一个元素.我的线性布局的xml如下:

<ListView>
<LinearLayout
    android:orientation="vertical" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="center_vertical"
    android:drawablePadding="14dip"
    android:paddingLeft="15dip"
    android:paddingRight="15dip">
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"/>
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
</ListView>
Run Code Online (Sandbox Code Playgroud)

如何在列表视图中获取此内容?当我尝试将其放入列表视图时,我在手机上收到错误提示抱歉!应用程序意外停止.请再试一次.堆栈跟踪如下.

I/dalvikvm( 1692): Debugger thread not active, ignoring DDM send (t=0x41504e4d l=38)
I/dalvikvm( 1692): Debugger thread not active, ignoring DDM send (t=0x41504e4d l=56)
D/AndroidRuntime( 1692): Shutting down VM
W/dalvikvm( 1692): threadid=3: thread exiting with uncaught exception (group=0x4001b170)
E/AndroidRuntime( 1692): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 1692): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.acme.activeisclickable/com.acme.activeisclickable.ActiveIsClickable}: java.lang.RuntimeException: Binary XML …
Run Code Online (Sandbox Code Playgroud)

android listview android-linearlayout

1
推荐指数
1
解决办法
2万
查看次数

Android:扩展中间组件的布局

我正在尝试创建以下布局.

+---------------------+
|     Text View       |
+---------------------+
|                     |
|                     |
|    Custom View      |
|    Expands to       |
|    extra space      |
|                     |
+---------------------+
|Button1   |Button2   |
+---------------------+
Run Code Online (Sandbox Code Playgroud)

我的布局xml如下所示.

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

    <TextView android:text="This is test text." android:id="@+id/statusTxt"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:id="@+id/gameView"
        android:layout_gravity="bottom">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="horizontal" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/gameButtonView">

            <Button android:text="Done" android:id="@+id/doneBtn"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

            <Button android:text="Undo" android:id="@+id/undoBtn"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

比编程我添加自定义视图

LinearLayout gameView = (LinearLayout)this.findViewById(R.id.gameView);
gameView.addView(gameBoardView, …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-linearlayout

1
推荐指数
1
解决办法
2560
查看次数

布局重量警告嵌套重量不良表现

我是android的新手.现在我收到了嵌套重量不良表现的警告.我的第一个屏幕上只有一个图像和三个按钮.PLs给了我一些想法.


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/backgroundColor"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:weightSum="10"
    >


    <ImageView
        android:layout_weight="4"
        android:id="@+id/imageLogo"
        android:layout_width="wrap_content" 
        android:layout_height="0dip"
        android:contentDescription="@string/Img"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="20dp"
        android:src="@drawable/home_screen_logo" />

    <LinearLayout
       android:layout_weight="6"
       android:layout_width="fill_parent"
    android:layout_height="0dip" 
    android:orientation="vertical" 
    android:gravity="center_horizontal"
        >

        <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent"
            android:layout_weight="1"
            android:id="@+id/temp"></LinearLayout>
    <ImageButton
        android:id="@+id/btnLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/login"
        android:contentDescription="@string/Img"  
        android:layout_weight="1"
        />
    <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent"
            android:layout_weight="1"></LinearLayout>
    <ImageButton
        android:id="@+id/btnFbLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
         android:background="@drawable/btnfb"
         android:contentDescription="@string/Img"
        />
    <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent"
            android:layout_weight="1"></LinearLayout>
    <ImageButton
        android:id="@+id/btnRegister"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/btnregister"
        android:contentDescription="@string/Img"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)


提前致谢

android android-linearlayout

1
推荐指数
1
解决办法
5440
查看次数

以编程方式创建多个线性布局和分隔符

在我的应用程序中 有活动包含多个线性布局和分隔符,它以编程方式创建,运行正常,

但我必须复制线性布局和分隔线5次,除了两件事以外都是一样的:

1-每个线性布局都有不同的字符串.

2-第一分频器余量不同于其他分频器余量.

是否有更好的方法来做更干净和更短的代码.

任何帮助都感激不尽 .

public class Dreams extends Activity {

@Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Boolean customTitleSupported =  
      requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
     setContentView(R.layout.trip);  
     if (customTitleSupported) { 

  getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
  } 
         TextView tv = (TextView) findViewById(R.id.title); 
         tv.setTypeface(FontFactory.getOldEnglish(getBaseContext()));
         tv.setText("Dreams");  

     LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout);       
        // add text view
        TextView tv1 = new TextView(this);
        tv1.setGravity(Gravity.RIGHT);
        tv1.setTextSize(30);    
        tv1.setTypeface(FontFactory.getOldEnglish(getBaseContext()));
        ll.addView(tv1);
        tv1.setText(Html.fromHtml(getString(R.string.dreams))); 

        ImageView divider1 = new ImageView(this);
        LinearLayout.LayoutParams lp1 = 
         new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 5);
        lp1.setMargins(40, 0, 40, 0);
        divider1.setLayoutParams(lp1);
        divider1.setBackgroundColor(Color.RED);
        ll.addView(divider1); …
Run Code Online (Sandbox Code Playgroud)

android android-linearlayout

1
推荐指数
1
解决办法
8894
查看次数

对齐ImageView以使文本视图保持中心,并在android xml中最右边的复选框

我正在使用RelativeLayout进行活动布局我希望图像视图位于最左侧,textview位于中心,复选框位于最右侧,但布局重力和重力不起作用请有人帮忙

 <?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="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageViewTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:gravity="left"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textViewTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Time" />

    <CheckBox
        android:id="@+id/checkBoxTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:=""
        android:gravity="right" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageViewCompass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:gravity="left"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textViewCompass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Compass" />

    <CheckBox
        android:id="@+id/checkBoxCompass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:gravity="right" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" > …
Run Code Online (Sandbox Code Playgroud)

android relativelayout android-layout android-linearlayout

1
推荐指数
1
解决办法
3158
查看次数

视图的高度和宽度始终为0(getMeasuredHeight()和getHeight()都不起作用)

我有一个LinearLayout内部LinearLayout和一个孩子linearlayout有它的layout params地方,height并被width定义为

LinearLayout linearLayout=new LinearLayout(context);
        LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(50,50);
        linearLayout.setLayoutParams(lp);
Run Code Online (Sandbox Code Playgroud)

现在后视图中创建我试图从获得一个视图的高度getHeight()getMeasuredHeight(),但是这两种方法返回0.?

  int heightofView=linearLayout.getHeight(); 
  int heightofview=linearLayout.getMeasuredHeight();
Run Code Online (Sandbox Code Playgroud)

为什么这两个方法都返回0视图的高度?当这些方法返回实际结果时?如何获得我创建的视图的高度?

java android android-layout android-linearlayout

1
推荐指数
1
解决办法
1640
查看次数

LinearLayout无法转换为CoordinatorLayout

我有个问题.我想以编程方式设置margin params,但它不起作用.我有这个xml样式表:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">


</android.support.design.widget.AppBarLayout>


<ImageView
    android:layout_width="1440px"
    android:layout_height="1000px"
    android:id="@+id/post_view_photo"
    android:transitionName="@string/transition_image"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|start"
    android:layout_margin="@dimen/fab_margin"
    app:layout_anchor="@+id/post_view_photo"
    android:src="@android:drawable/stat_notify_chat"
    app:layout_anchorGravity="bottom|end" />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_anchor="@+id/post_view_photo"
    app:layout_anchorGravity="bottom|start">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text_bar"
        android:background="@color/colorPrimary">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/username_text"
            android:layout_gravity="center_vertical|start"
            app:layout_anchor="@+id/post_view_photo"
            app:layout_anchorGravity="bottom|start"
            android:textSize="25dp"
            android:transitionName="@string/transition_username"/>
    </LinearLayout>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginTop="808px"
    android:id="@+id/view_bottom_layout">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <ImageView
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:id="@+id/post_user_image"
                android:src="@drawable/back"
                android:paddingTop="10px"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/post_view_maintext"/>
        </LinearLayout>

    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#414141"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我想以编程方式设置边距.但我得到这个错误:

java.lang.ClassCastException: android.support.design.widget.CoordinatorLayout$LayoutParams cannot be …
Run Code Online (Sandbox Code Playgroud)

xml android android-linearlayout android-activity

1
推荐指数
1
解决办法
4585
查看次数

单击textview后禁用单击

我有一个TextView,我OnClickListener对此放了一个TextView。我使用此操作将自定义视图加载到LinearLayout

但是,当我单击TextView两次时,自定义视图在上重复LinearLayoutLinearLayout在将新的自定义视图加载到this 之前,我会清除所有自定义视图LinearLaout

这是我OnClickListenerTextView

TextView rejectedTitleTextView = (TextView) findViewById(R.id.roster_menu_rejected_title);

rejectedTitleTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rejectedTitleTextView.setBackgroundColor(getResources().getColor(R.color.acceptedPurpleColour));
                newTitleTextView.setBackgroundColor(getResources().getColor(R.color.defaultBlack));
                acceptedTitleTextView.setBackgroundColor(getResources().getColor(R.color.defaultBlack));

                locationLinearLayout.removeAllViews();
                rosterBottomLayout.setVisibility(View.GONE);

                Log.d("CHECK_ACTION"," REJECTED_TEXT_VIEW ");

                InternetConnectivity internetConnectivity = new InternetConnectivity();
                final boolean isConnectedToInternet = internetConnectivity.isConnectedToInternet(context);

                if(isConnectedToInternet==true) {
                    try {
                        Thread.sleep(1300);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    getDataFromServer("REJECTED");
                }else{
                        Snackbar.make(mainView, "No Internet Connection", Snackbar.LENGTH_LONG)
                                .setAction("Action", null).show();
                }

            }
        }); …
Run Code Online (Sandbox Code Playgroud)

android textview android-layout android-linearlayout onclicklistener

1
推荐指数
2
解决办法
4057
查看次数