我在线性布局中有一个textview。我将textview设置为match_parent,包括高度和宽度。
本质上,textview是屏幕的大小。但是文本与左上角保持一致。有没有办法让它居中?
我有android:gravity和android:textAlignment设置为居中。
<!doctype html>
<html>
<head>
<title>Socket.IO</title>
</head>
<body>
<ul id="messages">
<li>Hardcoded Message</li>
</ul>
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
var socket = io();
socket.on("test-channel", function(message) {
console.log(message);
$('#messages').append($('<li>').text(message));
});
</script>
</body>
</html>
答案 0 :(得分:0)
使用
controllers.tests.js
或只是
describe('Controllers', function() {
beforeEach(module('myApp.services', 'myApp.controllers'));
var mockRequest = {
}
beforeEach(function() {
module(function($provide) {
$provide.value('initiateRequest', mockRequest);
});
});
var $rootScope, $controller, $sharedProperties, $resource;
beforeEach(inject(function(_$controller_, $rootScope) {
myScope = $rootScope.$new();
$scope = {};
$state = {};
LoginService = {};
localStorageService = {};
sharedProperties = {};
$ionicLoading = myScope;
initiateRequest = mockRequest;
$controller = _$controller_;
}));
describe('$scope.login()', function() {
it('does something', function() {
var $scope = {};
var controller = $controller('LoginController', {
$scope: $scope,
$state: $state,
LoginService: LoginService,
localStorageService: localStorageService,
sharedProperties: sharedProperties,
$ionicLoading: $ionicLoading
});
expect($scope.login).toBeDefined(true);
expect($scope.show).toBeDefined(true);
$scope.login();
});
});
});
将文本置于TexView中心。
编辑:尝试删除android:gravity="center_vertical|center_horizontal"
或layout_weight属性
答案 1 :(得分:0)
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView"
android:layout_gravity="center"
android:layout_weight="1"
android:textAlignment="center" />
答案 2 :(得分:0)
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView"
android:layout_gravity="center"
android:layout_weight="1"
android:textAlignment="center" />