如何在Android布局文件中定义带下划线的文本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="@string/welcome"
android:id="@+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
<LinearLayout android:id="@+id/LinearLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom">
<EditText android:id="@+id/EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
<Button android:text="@string/label_submit_button"
android:id="@+id/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这看起来像在左边,我希望它看起来像在右边.

显而易见的答案是在高度上将TextView设置为fill_parent,但这不会为按钮或输入字段留下任何余地.本质上问题是我希望提交按钮和文本条目在底部是固定高度,文本视图填充剩余的空间,类似于水平线性布局我希望提交按钮包装其内容和用于填充剩余空间的文本条目.
如果线性布局中的第一个项目被告知fill_parent它就是这样做的,没有其他项目的空间,我如何获得一个线性布局中的第一个项目来填充除了其余项目所需的最小空间之外的所有空间布局中的项目?
编辑:
相对布局确实是答案 - 谢谢!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="@string/welcome"
android:id="@+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
</TextView>
<RelativeLayout
android:id="@+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:text="@string/label_submit_button"
android:id="@+id/Button"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<EditText
android:id="@+id/EditText"
android:layout_width="fill_parent"
android:layout_toLeftOf="@id/Button"
android:layout_height="wrap_content">
</EditText>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 现在,我将每个xml布局文件存储在res/layout文件夹中,因此管理小项目是可行且简单的,但是当存在大型和重型项目的情况时,则应该存在层次结构和子文件夹布局文件夹.
例如
layout
-- layout_personal
-- personal_detail.xml
-- personal_other.xml
--layout_address
-- address1.xml
-- address2.xml
Run Code Online (Sandbox Code Playgroud)
以同样的方式,我们希望有大型应用程序的子文件夹,所以有没有办法在android项目中这样做?
我可以在布局文件夹中创建layout-personal和layout_address子文件夹,但是当使用R.layout ._______访问xml布局文件的时候,当时内部没有任何xml布局弹出窗口.菜单.
我动态地在我的android项目中创建所有元素.我试图获得按钮的宽度和高度,以便我可以旋转该按钮.我只是想学习如何使用android语言.但是,它返回0.
我做了一些研究,我发现它需要在onCreate()方法之外的某个地方完成.如果有人能给我一个如何做的例子,那就太好了.
这是我目前的代码:
package com.animation;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.LinearLayout;
public class AnimateScreen extends Activity {
//Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 0);
Button bt = new Button(this);
bt.setText(String.valueOf(bt.getWidth()));
RotateAnimation ra = new RotateAnimation(0,360,bt.getWidth() / 2,bt.getHeight() / 2);
ra.setDuration(3000L);
ra.setRepeatMode(Animation.RESTART);
ra.setRepeatCount(Animation.INFINITE);
ra.setInterpolator(new LinearInterpolator());
bt.startAnimation(ra);
ll.addView(bt,layoutParams);
setContentView(ll);
} …Run Code Online (Sandbox Code Playgroud) 在Android API 11+中,Google发布了一个名为的新类Fragment.
在视频中,谷歌建议尽可能(link1,link2),我们应该使用片段而不是活动,但他们没有解释确切原因.
片段的目的是什么?它们的一些可能的用途(除了一些可以通过简单的视图/布局轻松实现的UI示例)?
我的问题是片段:
奖金问题:
android android-layout android-fragments android-3.0-honeycomb android-activity
我正在为Activity我的Android应用程序中的登录工作.下面的图片是我希望它看起来像:

我能够使用以下XML实现此布局.问题是,它有点hackish.我不得不为主机EditText硬编码宽度.具体来说,我必须指定:
android:layout_width="172dp"
Run Code Online (Sandbox Code Playgroud)
我真的想给主机和端口EditText提供一个百分比宽度.(主机为80%,端口为20%.)这可能吗?以下XML适用于我的Droid,但似乎并不适用于所有屏幕.我真的想要一个更强大的解决方案.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/host_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/home"
android:paddingLeft="15dp"
android:paddingTop="0dp"
android:text="host"
android:textColor="#a5d4e2"
android:textSize="25sp"
android:textStyle="normal" />
<TextView
android:id="@+id/port_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/home"
android:layout_toRightOf="@+id/host_input"
android:paddingTop="0dp"
android:text="port"
android:textColor="#a5d4e2"
android:textSize="25sp"
android:textStyle="normal" />
<EditText
android:id="@+id/host_input"
android:layout_width="172dp"
android:layout_height="wrap_content"
android:layout_below="@id/host_label"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="4dp"
android:background="@android:drawable/editbox_background"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/port_input"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="@id/host_label"
android:layout_marginTop="4dp"
android:layout_toRightOf="@id/host_input"
android:background="@android:drawable/editbox_background"
android:inputType="number" />
<TextView
android:id="@+id/username_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/host_input"
android:paddingLeft="15dp"
android:paddingTop="15dp"
android:text="username"
android:textColor="#a5d4e2"
android:textSize="25sp"
android:textStyle="normal" />
<EditText
android:id="@+id/username_input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username_label"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="4dp"
android:background="@android:drawable/editbox_background" …Run Code Online (Sandbox Code Playgroud) 我在Android中玩片段.
我知道我可以使用以下代码更改片段:
FragmentManager fragMgr = getSupportFragmentManager();
FragmentTransaction fragTrans = fragMgr.beginTransaction();
MyFragment myFragment = new MyFragment(); //my custom fragment
fragTrans.replace(android.R.id.content, myFragment);
fragTrans.addToBackStack(null);
fragTrans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
fragTrans.commit();
Run Code Online (Sandbox Code Playgroud)
我的问题是,在Java文件中,如何获取当前显示的Fragment实例?
我正在动态创建按钮.我首先使用XML设置它们,我正在尝试使用下面的XML并使其编程.
<Button
android:id="@+id/buttonIdDoesntMatter"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="buttonName"
android:drawableLeft="@drawable/imageWillChange"
android:onClick="listener"
android:layout_width="fill_parent">
</Button>
Run Code Online (Sandbox Code Playgroud)
这就是我到目前为止所拥有的.除了可绘制之外,我可以做任何事情.
linear = (LinearLayout) findViewById(R.id.LinearView);
Button button = new Button(this);
button.setText("Button");
button.setOnClickListener(listener);
button.setLayoutParams(
new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT
)
);
linear.addView(button);
Run Code Online (Sandbox Code Playgroud) 有谁知道如何实现像今天的一些顶级应用程序的滑动菜单?
其他Stack Overflow 问题对于如何做到这一点没有任何答案,所以我试图收集尽可能多的信息来帮助其他人.我在下面提到的所有应用程序都可以很好地实现幻灯片菜单.

您只能通过单击左上角的G +徽标从第一个屏幕转到第二个屏幕.请注意,整个屏幕从其位置移动并轻推到屏幕右侧(包括操作栏).要返回第一个屏幕,您可以将右侧滑回焦点,也可以再次单击G +图标.

您可以使用两种方法从第一个屏幕进入第二个屏幕.您可以点击左上角的YouTube徽标,也可以使用滑动手势将其移到右侧.这已经与G + app不同了.其次,您可以看到操作栏保持不变(与G +不同).最后,为了获得原始屏幕,它就像G +一样工作.