Textview的布局太低

时间:2016-06-27 12:15:33

标签: android

我在Android项目的布局中使用了TextView。我希望TextView在页面顶部的徽标下开始。但是,它从页面中间开始。我的编码与我所有其他页面完全相同,TextView在正确的位置开始。我不知道我能做些什么不同。有谁知道这是为什么,或/和我如何解决这个问题?这是我布局的图像,目前屏幕中间有文字,而我希望它在顶部。

Click here to see the image

这是我的XML代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:measureWithLargestChild="false"
    android:orientation="vertical"
    tools:context="com.example.rodekruis.Nieuws" >

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:src="@drawable/rkz_logo"
        android:layout_gravity="left" 
        android:layout_marginLeft="1dp"/>

     <ImageView
        android:id="@+id/imageButton1"
        android:layout_width="40dp"
        android:layout_height="50dp"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="10dp"
        android:layout_gravity="right" 
        android:src="@drawable/informatiebutton" />
 </FrameLayout>

     <ScrollView
         android:id="@+id/scrollview"
         android:layout_width="fill_parent"
         android:layout_height="364dp" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="244dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:layout_gravity="center"
        android:text="@string/title_activity_nieuws"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/black"
        android:autoLink="web" />

</ScrollView>

     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="15dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button11"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            android:text="Facebook" />

        <Button
            android:id="@+id/button12"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            android:text="Youtube" />

        <Button
            android:id="@+id/button13"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignLeft="@+id/button5"
            android:layout_below="@+id/button8"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:text="Twitter" />

        <Button
            android:id="@+id/button14"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignLeft="@+id/button5"
            android:layout_below="@+id/button8"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:text="LinkedIn" />

    </LinearLayout>
</LinearLayout>

这是我的主要活动代码:

package com.example.rodekruis;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Html;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;

public class NieuwsActivity extends Activity implements View.OnClickListener{


     TextView HyperLink;
     Spanned Text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nieuws);

        findViewById(R.id.button11).setOnClickListener(this);
        findViewById(R.id.button12).setOnClickListener(this);
        findViewById(R.id.button13).setOnClickListener(this);
        findViewById(R.id.button14).setOnClickListener(this);
        findViewById(R.id.imageButton1).setOnClickListener(this);

        TextView textView =(TextView)findViewById(R.id.textView);
        textView.setClickable(true);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        String text = getResources().getString(R.string.title_activity_nieuws);
        text += "<a href='https://www.rkz.nl/nieuws_agenda_nieuws'> Naar het nieuwsoverzicht </a>";
        textView.setText(Html.fromHtml(text));


    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {


            case R.id.button11:
                Uri uri = Uri.parse("https://www.facebook.com/RKZ.BrandwondencentrumBeverwijk");
                intent = new Intent(Intent.ACTION_VIEW, uri);
                break;
            case R.id.button12:
                Uri uri1 = Uri.parse("https://www.youtube.com/user/rodekruisziekenhuis/featured");
                intent = new Intent(Intent.ACTION_VIEW, uri1);
                break;
            case R.id.button13:
                Uri uri2 = Uri.parse("https://twitter.com/rodekruiszh?lang=nl");
                intent = new Intent(Intent.ACTION_VIEW, uri2);
                break;
            case R.id.button14:
                Uri uri3 = Uri.parse("https://www.linkedin.com/company/rode-kruis-ziekenhuis");
                intent = new Intent(Intent.ACTION_VIEW, uri3);
                break;
            case R.id.imageButton1:
                intent = new Intent(NieuwsActivity.this, InfoActivity.class);
                break;
        }
        startActivity(intent);
    }

}

2 个答案:

答案 0 :(得分:1)

android:layout_gravity="center"android:layout_gravity="top"更改为TextView应修复此问题。

据我所知,您的滚动视图为364p,而TextView在此处集中定位。您的意思是使用android:gravity="center",它会使TextView的内容而不是TextView本身的内容居中吗?

答案 1 :(得分:0)

在textview中更改此行:

android:layout_gravity="center"

android:layout_gravity="top"